Skip to content

Instantly share code, notes, and snippets.

@paramsen paramsen/build.groovy
Last active Jun 28, 2020

Embed
What would you like to do?
Generate Android version code from git count in Gradle (build.gradle)
// Generate a minor version code from git commit count (for prod builds)
static def generateVersionCode() {
def result = "git rev-list HEAD --count".execute().text.trim() //unix
if(result.empty) result = "PowerShell -Command git rev-list HEAD --count".execute().text.trim() //windows
if(result.empty) throw new RuntimeException("Could not generate versioncode on this platform? Cmd output: ${result.text}")
return result.toInteger()
}
def majorVersion = 1
android {
defaultConfig {
versionCode generateVersionCode()
versionName "${majorVersion}.${generateVersionCode()}"
}
}
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.