Use .buildcount file for unique auto-incrementing versionCode
Build counter is incremented by deploy.ps1 on every deploy, ensuring unique versionCode even from the same commit. File is gitignored.
This commit is contained in:
@@ -14,18 +14,19 @@ fun gitVersionName(): String = runGit("describe", "--tags", "--abbrev=0")
|
||||
.removePrefix("v")
|
||||
.ifEmpty { "0.1.0" }
|
||||
|
||||
// Build number = total commits (always increments) + offset for store history
|
||||
const val VERSION_CODE_OFFSET = 4
|
||||
fun gitBuildNumber(): Int = (runGit("rev-list", "--count", "HEAD")
|
||||
.toIntOrNull() ?: 1) + VERSION_CODE_OFFSET
|
||||
// Build number from .buildcount file (incremented by deploy.ps1)
|
||||
fun buildNumber(): Int {
|
||||
val file = rootProject.file(".buildcount")
|
||||
return if (file.exists()) file.readText().trim().toIntOrNull() ?: 1 else 1
|
||||
}
|
||||
|
||||
fun gitShortHash(): String = runGit("rev-parse", "--short", "HEAD")
|
||||
.ifEmpty { "unknown" }
|
||||
|
||||
// Display: "0.1.0+5.abc1234"
|
||||
// Display: "0.1.0+6.abc1234"
|
||||
fun gitDisplayVersion(): String {
|
||||
val base = gitVersionName()
|
||||
val build = gitBuildNumber()
|
||||
val build = buildNumber()
|
||||
val hash = gitShortHash()
|
||||
return "$base+$build.$hash"
|
||||
}
|
||||
@@ -63,7 +64,7 @@ android {
|
||||
applicationId = "com.omixlab.lckcontrol"
|
||||
minSdk = 32
|
||||
targetSdk = 34
|
||||
versionCode = gitBuildNumber()
|
||||
versionCode = buildNumber()
|
||||
versionName = gitVersionName()
|
||||
|
||||
buildConfigField("String", "DISPLAY_VERSION", "\"${gitDisplayVersion()}\"")
|
||||
|
||||
Reference in New Issue
Block a user