From fa2af6dd9030bcb7686b90fd413a04d22ca219c4 Mon Sep 17 00:00:00 2001 From: Thomas Andres Gomez Date: Sun, 9 May 2021 12:03:00 +0200 Subject: [PATCH] Add dynamic version code. --- app/build.gradle | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 463bda3..217a492 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,7 +12,7 @@ android { applicationId "com.pixelized.biblib" minSdk 23 targetSdk 30 - versionCode 1 + versionCode generateVersionCode() versionName "0.1.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -105,4 +105,11 @@ dependencies { // Test testImplementation 'junit:junit:4.13.2' androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.0.0-beta06" +} + +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() } \ No newline at end of file