Skip to content

Instantly share code, notes, and snippets.

@doridori doridori/build.gradle
Last active Apr 21, 2017

Embed
What would you like to do?
Incrementing android VersionCode via gradle
//in your root build.gradle
//--------- Version Increment ----------//
//can call this like `./gradlew incrementVersionCode build`
task incrementVersionCode {
description = "Increments the version code in the version.properties file"
doLast {
File versionPropsFile = file('version.properties')
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def code = versionProps['VERSION_CODE'].toInteger() + 1
versionProps['VERSION_CODE'] = code.toString()
versionProps.store(versionPropsFile.newWriter(), null)
println "VERSION_CODE incremented to "+code
} else {
throw new GradleException("Could not read version.properties!")
}
}
}
//can call this from your android DSL
int getIncrementingVersionCode() {
def versionPropsFile = file('version.properties')
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def code = versionProps['VERSION_CODE'].toInteger()
return 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
You can’t perform that action at this time.