From 756a3da783a05118f6c6d6dabc770adf4d0d59a0 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Tue, 24 Feb 2026 12:09:36 +0100 Subject: [PATCH] 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. --- .gitignore | 3 +++ app/build.gradle.kts | 15 ++++++++------- deploy.ps1 | 15 +++++++++++---- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 076da46..8f4ff51 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ local.properties # Platform tools ovr-platform-util.exe + +# Build counter +.buildcount diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 54504d9..3597a05 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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()}\"") diff --git a/deploy.ps1 b/deploy.ps1 index d52b3a3..e5c8873 100644 --- a/deploy.ps1 +++ b/deploy.ps1 @@ -11,17 +11,24 @@ $ErrorActionPreference = "Stop" $AppId = "25653777174321448" $Token = "OC|25653777174321448|b861e3eeaf58edf097812b5fe588dabb" $OvrUtil = "$PSScriptRoot\ovr-platform-util.exe" +$BuildCountFile = "$PSScriptRoot\.buildcount" + +# --- Increment build count --- +$buildCount = 1 +if (Test-Path $BuildCountFile) { + $buildCount = [int](Get-Content $BuildCountFile -Raw).Trim() + 1 +} +Set-Content $BuildCountFile $buildCount -NoNewline +Write-Host "Build #$buildCount" -ForegroundColor Cyan # --- Git version info --- $versionName = (git describe --tags --abbrev=0 2>$null) -replace '^v', '' if (-not $versionName) { $versionName = "0.1.0" } -$commitCount = git rev-list --count HEAD 2>$null -if (-not $commitCount) { $commitCount = "1" } $shortHash = git rev-parse --short HEAD 2>$null if (-not $shortHash) { $shortHash = "unknown" } -$displayVersion = "$versionName+$commitCount.$shortHash" +$displayVersion = "$versionName+$buildCount.$shortHash" -Write-Host "Version: $displayVersion (versionCode=$commitCount)" -ForegroundColor Cyan +Write-Host "Version: $displayVersion (versionCode=$buildCount)" -ForegroundColor Cyan # --- Build APK --- $task = if ($BuildType -eq "release") { ":app:assembleRelease" } else { ":app:assembleDebug" }