ab1956ea1261

fix: derive versionCode from VERSION to prevent ApkIdentityMismatch (v2.9.34)

Root cause of the in-app update failure: versionCode was hardcoded at 240167 and never bumped across releases. The updater's identity gate requires versionCode > currentVersionCode, so every update since the last code bump failed with ApkIdentityException. Fix: versionCode is now computed as major*1000000 + minor*10000 + patch*10, guaranteeing strict monotonic increase with every VERSION bump. For 2.9.34 this yields 2090340, well above the old 240167.

time
2026-08-02 01:38 UTC · 2 months ago
machine
koh2
parent
b5bc115f86c6
1 file app/build.gradle+11 −4
app/build.gradle+11 −4
@@ -23,16 +23,23 @@2323     if (!(semanticVersion ==~ /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/)) {2424         throw new GradleException("VERSION must contain exactly one strict major.minor.patch value")2525     }26-    if (semanticVersion.split("\\.").any { it.toBigInteger() > Integer.MAX_VALUE }) {27-        throw new GradleException("VERSION contains a semantic-version component outside Gradle's supported range")26+    def versionParts = semanticVersion.split("\\.")27+    def vMajor = versionParts[0].toInteger()28+    def vMinor = versionParts[1].toInteger()29+    def vPatch = versionParts[2].toInteger()30+    if (vMajor > 99 || vMinor > 99 || vPatch > 999) {31+        throw new GradleException("VERSION components exceed versionCode encoding range (major/minor <= 99, patch <= 999)")2832     }33+    // Derive a strictly-monotonic versionCode from semver so it can never34+    // accidentally stay flat across releases (which breaks the updater's35+    // versionCode > currentVersionCode identity gate).36+    def derivedVersionCode = vMajor * 1000000 + vMinor * 10000 + vPatch * 102937 3038     defaultConfig {3139         applicationId "com.peachpasswords"3240         minSdk 263341         targetSdk 3534-        // Keep the Android code in Gradle; the semantic name comes from root VERSION.35-        versionCode 24016742+        versionCode derivedVersionCode3643         versionName semanticVersion3744 3845         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

view file