Skip to content

Instantly share code, notes, and snippets.

@rob-murray
Last active December 23, 2015 09:19
Show Gist options
  • Save rob-murray/6614211 to your computer and use it in GitHub Desktop.
Save rob-murray/6614211 to your computer and use it in GitHub Desktop.
How to increment the Android version code using Gradle Android build system
// add method to get the versionCode from cli param
// eg. `gradle tasks -PversionCode=999`
/**
* Get the version code from command line param
*
* @return int If the param -PversionCode is present then return int value or -1
*/
def getVersionCode = { ->
def code = project.hasProperty('versionCode') ? versionCode.toInteger() : -1
println "VersionCode is set to $code"
return code
}
// add to defaultConfig
android {
defaultConfig {
versionCode getVersionCode()
//...
}
}
@quentin7b
Copy link

getVersionCode wasn't working for me (gradle plugin version 0.12), never called (no output).
Guess it was kind of protected accessor
So I just replaced getVersionCode by guessVersionCode and now works like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment