Last active
January 17, 2024 08:17
-
-
Save paramsen/4a92c9230d799caeb3b90897da27a80c 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