Skip to content

Instantly share code, notes, and snippets.

@dominicthomas
Created September 30, 2015 09:43
Show Gist options
  • Save dominicthomas/06124c874d5ccc5ca0c1 to your computer and use it in GitHub Desktop.
Save dominicthomas/06124c874d5ccc5ca0c1 to your computer and use it in GitHub Desktop.
Simple way of incrementing the app versionCode when a particular task is run. Useful to increment versionCode when doing a production release build.
// Increment version code when running a production release
def versionPropsFile = file('version.properties')
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def value = 0
def runTasks = gradle.startParameter.taskNames
if ('assembleProductionRelease' in runTasks) {
value = 1;
}
def version_Code = versionProps['VERSION_CODE'].toInteger() + value
versionProps['VERSION_CODE'] = version_Code.toString()
versionProps.store(versionPropsFile.newWriter(), null)
defaultConfig {
versionCode version_Code
}
} else {
throw new GradleException("Could not read version.properties!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment