Skip to content

Instantly share code, notes, and snippets.

@ziglee
Created January 12, 2018 13:47
Show Gist options
  • Save ziglee/6c14a85d3eeb5919013658e703ea9386 to your computer and use it in GitHub Desktop.
Save ziglee/6c14a85d3eeb5919013658e703ea9386 to your computer and use it in GitHub Desktop.
Build gradle excerpt that uses Jenkins BUILD_NUMBER to compose the versionCode in AndroidManifest.xml
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.25.1'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
// Used to set the package version name and version code
ext {
versionMajor = 1
versionMinor = 2
}
android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.mypackage"
minSdkVersion 16
targetSdkVersion 25
versionName computeVersionName()
versionCode computeVersionCode()
}
...
}
...
def computeVersionName() {
// Basic <major>.<minor> version name
return String.format('%d.%d', versionMajor, versionMinor)
}
// Will return 120042 for Jenkins build #42
def computeVersionCode() {
// Major + minor + Jenkins build number (where available)
return (versionMajor * 100000) + (versionMinor * 10000) + Integer.valueOf(System.env.BUILD_NUMBER ?: 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment