From 9895ed10615e33912e7fc074cc23efdd2c7086a1 Mon Sep 17 00:00:00 2001 From: Zane Schepke Date: Mon, 16 Sep 2024 01:31:26 -0400 Subject: [PATCH] fix: versionCode increment --- app/build.gradle.kts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1f9d969..00849b8 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -10,6 +10,13 @@ plugins { alias(libs.plugins.grgit) } +val versionFile = file("$rootDir/versionCode.txt") +val versionCodeIncrement = if (versionFile.exists()) { + versionFile.readText().toInt() + 1 +} else { + 1 +} + android { namespace = Constants.APP_ID compileSdk = Constants.TARGET_SDK @@ -22,7 +29,7 @@ android { applicationId = Constants.APP_ID minSdk = Constants.MIN_SDK targetSdk = Constants.TARGET_SDK - versionCode = Constants.VERSION_CODE + (versionCode ?: 0) + versionCode = Constants.VERSION_CODE + versionCodeIncrement versionName = determineVersionName() ksp { arg("room.schemaLocation", "$projectDir/schemas") } @@ -214,15 +221,11 @@ fun determineVersionName(): String { val incrementVersionCode by tasks.registering { doLast { - val versionCodeFile = file("$rootDir/versionCode.txt") - val currentVersionCode = if (versionCodeFile.exists()) { - versionCodeFile.readText().toInt() - } else { - 1 + val versionFile = file("$rootDir/versionCode.txt") + if (versionFile.exists()) { + versionFile.writeText(versionCodeIncrement.toString()) + println("Incremented versionCode to $versionCodeIncrement") } - val newVersionCode = currentVersionCode + 1 - versionCodeFile.writeText(newVersionCode.toString()) - println("Incremented versionCode to $newVersionCode") } }