#!/usr/bin/env sh # Pin an explicit, monotonic Android versionCode. # # `tauri android init` derives one from the semver in a way that is not # monotonic across a version series: 0.1.0 and 0.0.10 can collide, and Android # refuses to install an APK whose versionCode is not greater than the installed # one. A rider who cannot update is a rider who stops updating. # # code = 1000 + major * 10000 + minor * 100 + patch # # so 0.1.0 -> 1100, 0.1.3 -> 1103, 0.2.0 -> 1200, 1.0.0 -> 11000. Monotonic in # semver order for any minor/patch below 100, which is well past where this # project will ever get. # # The 1000 floor is not decoration: `tauri android init` writes versionCode=1000 # for 0.1.0 today, so anyone carrying a locally-built APK already has that # number installed. A bare major/minor/patch code would be 100 — a *downgrade*, # which Android refuses outright. # # POSIX sh: the runner's /bin/sh is dash. No here-strings, no \s in sed. set -e ROOT="$(cd "$(dirname "$0")/.." && pwd)" PROPS="$ROOT/src-tauri/gen/android/app/tauri.properties" CONF="$ROOT/src-tauri/tauri.conf.json" [ -f "$PROPS" ] || { echo "❌ $PROPS not found — run 'cargo tauri android init' first" >&2; exit 1; } VERSION=$(grep '"version"' "$CONF" | head -1 | sed -E 's/.*"version"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/') MAJ=$(echo "$VERSION" | cut -d. -f1) MIN=$(echo "$VERSION" | cut -d. -f2) PAT=$(echo "$VERSION" | cut -d. -f3) # Guard a malformed or short version so we can never emit code 0, which Android # treats as "older than everything". : "${MAJ:=0}" "${MIN:=0}" "${PAT:=0}" CODE=$(( 1000 + MAJ * 10000 + MIN * 100 + PAT )) echo "version=$VERSION -> versionCode=$CODE" if grep -q '^tauri.android.versionCode=' "$PROPS"; then sed -i "s/^tauri.android.versionCode=.*/tauri.android.versionCode=$CODE/" "$PROPS" else echo "tauri.android.versionCode=$CODE" >> "$PROPS" fi cat "$PROPS"