From 999d41207922740233782acd617525e2cd77b801 Mon Sep 17 00:00:00 2001 From: "Aleksandr.ru" Date: Sat, 11 Mar 2023 15:42:02 +0300 Subject: [PATCH] build version increment for debug --- app/build.gradle | 53 ++++++++++++++++++++++++++++-------------- app/version.properties | 4 ++-- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 714c2ae..dcc1b6e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,3 +1,30 @@ +def getVerCode() { + // https://stackoverflow.com/a/58880410 + def versionPropsFile = file('version.properties') + if (versionPropsFile.canRead()) { + Properties versionProps = new Properties() + versionProps.load(new FileInputStream(versionPropsFile)) + def code = versionProps['VERSION_CODE'].toInteger() + + gradle.taskGraph.whenReady { graph -> + List tasks = graph.getAllTasks() + for (Task t : tasks) { + if (t.name.contains("assembleDebug")) { + code += 1 + versionProps['VERSION_CODE'] = code.toString() + versionProps.store(versionPropsFile.newWriter(), null) + break + } + } + } + + return code + } + else { + throw new GradleException("Could not read version.properties!") + } +} + plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' @@ -7,26 +34,16 @@ android { namespace 'ru.aleksandr.dccppthrottle' compileSdk 32 - def versionPropsFile = file('version.properties') - if (versionPropsFile.canRead()) { - Properties versionProps = new Properties() - versionProps.load(new FileInputStream(versionPropsFile)) - def code = versionProps['VERSION_CODE'].toInteger() + 1 - versionProps['VERSION_CODE']=code.toString() - versionProps.store(versionPropsFile.newWriter(), null) + def code = getVerCode() - defaultConfig { - applicationId "ru.aleksandr.dccppthrottle" - minSdk 21 - targetSdk 32 - versionCode code - versionName "1.0" + defaultConfig { + applicationId "ru.aleksandr.dccppthrottle" + minSdk 21 + targetSdk 32 + versionCode code + versionName "1.0" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - } - else { - throw new GradleException("Could not read version.properties!") + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/version.properties b/app/version.properties index 953a4ca..96bb0b8 100644 --- a/app/version.properties +++ b/app/version.properties @@ -1,2 +1,2 @@ -#Sat Mar 11 12:08:37 MSK 2023 -VERSION_CODE=641 +#Sat Mar 11 15:39:01 MSK 2023 +VERSION_CODE=659