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:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -18,3 +18,6 @@ local.properties
|
||||
|
||||
# Platform tools
|
||||
ovr-platform-util.exe
|
||||
|
||||
# Build counter
|
||||
.buildcount
|
||||
|
||||
@@ -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()}\"")
|
||||
|
||||
15
deploy.ps1
15
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" }
|
||||
|
||||
Reference in New Issue
Block a user