Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Increments the android versionCode automatically on each debug or release build
task('increaseVersionCode') << {
def manifestFile = file("src/main/AndroidManifest.xml")
def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
def matcher = pattern.matcher((CharSequence)manifestFile.getText())
matcher.find()
def versionCode = Integer.parseInt(matcher.group(1))
manifestFile.write(matcher.replaceAll("versionCode=\"" + ++versionCode + "\""))
}
assembleDebug.dependsOn 'increaseVersionCode'
assembleRelease.dependsOn 'increaseVersionCode'
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.