From 686f57252c046819272455059dc8dec3343c3916 Mon Sep 17 00:00:00 2001 From: funman300 Date: Sat, 16 May 2026 10:34:08 -0700 Subject: [PATCH] fix(android): stamp versionCode and versionName from the release tag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AndroidManifest.xml had hardcoded versionCode=1 / versionName=1.0, so every shipped APK looked identical to Android and Obtainium could never confirm the installed version matched the latest release tag — causing a persistent false-update notification loop. VERSION_NAME is now passed into the build script from the CI tag (e.g. "v0.28.0" → versionCode=2800, versionName="0.28.0") and forwarded to aapt2 link via --version-code / --version-name, overriding the manifest without touching the file. Co-Authored-By: Claude Sonnet 4.6 --- .gitea/workflows/android-release.yml | 1 + scripts/build_android_apk.sh | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/.gitea/workflows/android-release.yml b/.gitea/workflows/android-release.yml index 45f9b3b..4d7449f 100644 --- a/.gitea/workflows/android-release.yml +++ b/.gitea/workflows/android-release.yml @@ -81,6 +81,7 @@ jobs: KEYSTORE_PASS: ${{ secrets.RELEASE_KEYSTORE_PASS }} KEY_ALIAS: release KEY_PASS: ${{ secrets.RELEASE_KEYSTORE_PASS }} + VERSION_NAME: ${{ steps.tag.outputs.name }} run: bash scripts/build_android_apk.sh - name: Get tag name diff --git a/scripts/build_android_apk.sh b/scripts/build_android_apk.sh index f11ad78..6e8fc2c 100755 --- a/scripts/build_android_apk.sh +++ b/scripts/build_android_apk.sh @@ -75,12 +75,23 @@ if [ -d "$RES_DIR" ]; then "$BT/aapt2" compile --dir "$RES_DIR" -o "$STAGING/compiled-res" fi +# Derive versionCode/versionName from VERSION_NAME env var (e.g. "v0.28.0" → code 2800, name "0.28.0"). +# Falls back to the values hardcoded in AndroidManifest.xml when not set (local debug builds). +VERSION_CODE="" +if [ -n "${VERSION_NAME:-}" ]; then + VN="${VERSION_NAME#v}" + IFS='.' read -r _MAJ _MIN _PAT <<< "$VN" + VERSION_CODE=$(( ${_MAJ:-0} * 10000 + ${_MIN:-0} * 100 + ${_PAT:-0} )) +fi + LINK_ARGS=( link -o "$STAGING/app-unsigned.apk" -I "$PLATFORM_JAR" --manifest "$MANIFEST" ) +[ -n "$VERSION_CODE" ] && LINK_ARGS+=( --version-code "$VERSION_CODE" ) +[ -n "${VERSION_NAME:-}" ] && LINK_ARGS+=( --version-name "${VERSION_NAME#v}" ) [ -d "$ASSETS_DIR" ] && LINK_ARGS+=( -A "$ASSETS_DIR" ) # Add compiled resources if any shopt -s nullglob