Skip to content

Instantly share code, notes, and snippets.

@augustomen
Created June 13, 2018 14:30
Show Gist options
  • Save augustomen/a8bb0a89fefdd166ccf89a082a20a5d4 to your computer and use it in GitHub Desktop.
Save augustomen/a8bb0a89fefdd166ccf89a082a20a5d4 to your computer and use it in GitHub Desktop.
Obtain Android versionCode from git commit count
def loadVersionCode() {
def code = 1
new ByteArrayOutputStream().withStream { os ->
exec {
commandLine 'git', 'rev-list', 'HEAD', '--count'
standardOutput = os
}
code = os.toString().toInteger()
}
println "Version Code: $code"
return code
}
android {
defaultConfig {
...
versionCode loadVersionCode()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment