Skip to content

Instantly share code, notes, and snippets.

@heyarne
Created February 3, 2017 13:40
Show Gist options
  • Save heyarne/d9295b6382d2345adafa4a076d0a348c to your computer and use it in GitHub Desktop.
Save heyarne/d9295b6382d2345adafa4a076d0a348c to your computer and use it in GitHub Desktop.
Android build version with git commit hash
// merge this with your current build.gradle
// generates a version name from currently checked out git commit
def getCommitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
android {
// ...
defaultConfig {
// ...
versionName '1-' + getCommitHash()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment