Skip to content

Instantly share code, notes, and snippets.

@Numan1617
Created March 26, 2014 13:45
Show Gist options
  • Save Numan1617/9783467 to your computer and use it in GitHub Desktop.
Save Numan1617/9783467 to your computer and use it in GitHub Desktop.
Android - Automatic Version Numbering
def getVersionCode = { ->
try {
def code = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', 'HEAD', '--count'
standardOutput = code
}
return code.toString().toInteger()
}
catch (ignored) {
return -1;
}
}
def getVersionName = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags'
standardOutput = stdout
}
return stdout.toString().trim().split(/-/)[0]
}
catch (ignored) {
return null;
}
}
android {
defaultConfig {
versionCode getVersionCode()
versionName getVersionName()+'.'+getVersionCode()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment