Last active
December 23, 2015 09:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() | |
//... | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
byguessVersionCode
and now works like a charm.