-
-
Save bungabear/c37e2dc5b1382c89cd5df3277d65a7cd to your computer and use it in GitHub Desktop.
Generate Android version code from git count in Gradle (build.gradle)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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