Skip to content

Instantly share code, notes, and snippets.

@tuanchauict
Last active October 14, 2016 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuanchauict/bdcbbf6072c99f775762ad58e6f3e67c to your computer and use it in GitHub Desktop.
Save tuanchauict/bdcbbf6072c99f775762ad58e6f3e67c to your computer and use it in GitHub Desktop.
Auto increment version code and version name. This gist borrows heavily the code from https://gist.github.com/luciofm/923a9f35f2175dda7ad7.
//module gradle
apply from: 'versionCode.gradle' //anywhere
android {
defaultConfig {
versionName VERSION_NAME
versionCode Integer.parseInt(VERSION_CODE)
}
}
//module directory
VERSION_NAME=1.0.1
VERSION_CODE=1
//module directory
task('increaseVersionCode') << {
def versionCode = Integer.parseInt(VERSION_CODE) + 1
def versionName = VERSION_NAME.split("\\.")
def last = Integer.parseInt(versionName[versionName.length - 1])
versionName[versionName.length - 1] = Integer.toString(last + 1)
versionName = versionName.join(".")
ant.propertyfile(file: "gradle.properties") {
entry(key: "VERSION_CODE", value: versionCode)
entry(key: "VERSION_NAME", value: versionName)
}
}
tasks.whenTaskAdded { task ->
if (task.name == 'generateReleaseBuildConfig') {
task.dependsOn('increaseVersionCode')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment