Skip to content

Instantly share code, notes, and snippets.

@luizcarvalho
Forked from felipecsl/incrementVersionCode
Created December 11, 2013 12:43
Show Gist options
  • Save luizcarvalho/7909788 to your computer and use it in GitHub Desktop.
Save luizcarvalho/7909788 to your computer and use it in GitHub Desktop.
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