diff --git a/app/build.gradle b/app/build.gradle index 6c3ee1b..e5a9991 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,33 +3,7 @@ plugins { id 'org.jetbrains.kotlin.android' } -def getVersionCode = { -> - try { - def stdout = new ByteArrayOutputStream() - exec { - commandLine 'git', 'rev-list', '--first-parent', '--count', 'master' - standardOutput = stdout - } - return Integer.parseInt(stdout.toString().trim()) - } - catch (ignored) { - return -1; - } -} - -def getVersionName = { -> - try { - def stdout = new ByteArrayOutputStream() - exec { - commandLine 'git', 'describe', '--always', '--tags', '--dirty' - standardOutput = stdout - } - return stdout.toString().trim() - } - catch (ignored) { - return null; - } -} +apply from: '../helpers.gradle' // Signing config, mainly intended for debug builds def keystorePropertiesFile = rootProject.file("keystore.properties"); @@ -43,8 +17,8 @@ android { applicationId "im.angry.openeuicc" minSdk 30 targetSdk 31 - versionCode getVersionCode() - versionName getVersionName() + versionCode getGitVersionCode() + versionName getGitVersionName() testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -67,7 +41,7 @@ android { signingConfig signingConfigs.config } } - applicationVariants.all { variant -> + applicationVariants.configureEach { variant -> if (variant.name == "debug") { variant.outputs.each { o -> o.versionCodeOverride = System.currentTimeSeconds() } } diff --git a/helpers.gradle b/helpers.gradle new file mode 100644 index 0000000..f71e632 --- /dev/null +++ b/helpers.gradle @@ -0,0 +1,27 @@ +ext.getGitVersionCode = { -> + try { + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'rev-list', '--first-parent', '--count', 'master' + standardOutput = stdout + } + return Integer.parseInt(stdout.toString().trim()) + } + catch (ignored) { + return -1; + } +} + +ext.getGitVersionName = { -> + try { + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'describe', '--always', '--tags', '--dirty' + standardOutput = stdout + } + return stdout.toString().trim() + } + catch (ignored) { + return null; + } +} \ No newline at end of file