Skip to content

Commit

Permalink
build version increment for debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandr-ru committed Mar 11, 2023
1 parent a471f83 commit 999d412
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
53 changes: 35 additions & 18 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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<Task> 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'
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions app/version.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 999d412

Please sign in to comment.