Vectrum
Sign In

Android app takes the desktop app's version from Cargo.toml

versionName is the Cargo version and versionCode is
major * 1000000 + minor * 1000 + patch, so build.sh -v bumps both apps.
build.sh -a names the APK after the version and checks the built APK
carries it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
JjohannSocommitted 1 parent 64dd20acommitc98d9ee

Showing 2 changed files with 29 additions and 17 deletions.

+13−2android/app/build.gradle.ktsView File
@@ -4,6 +4,17 @@ plugins {
44 alias(libs.plugins.kotlin.serialization)
55 }
66
7+ // The app carries the desktop app's version from Cargo.toml: 0.1.9-local is
8+ // versionName 0.1.9-local and versionCode 1009 (major * 1000000 + minor * 1000 + patch).
9+ val desktopVersion: String = providers.fileContents(rootProject.layout.projectDirectory.file("../Cargo.toml"))
10+ .asText.get().lineSequence()
11+ .firstNotNullOf { Regex("""^version\s*=\s*"(.+)"""").find(it)?.groupValues?.get(1) }
12+ val desktopVersionCode: Int = desktopVersion.substringBefore('-').substringBefore('+').split('.').map(String::toInt)
13+ .let { (major, minor, patch) ->
14+ require(minor < 1000 && patch < 1000) { "Version $desktopVersion doesn't fit a versionCode" }
15+ major * 1_000_000 + minor * 1_000 + patch
16+ }
17+
718 android {
819 namespace = "cc.vectrum.code"
920 compileSdk = 37
@@ -12,8 +23,8 @@ android {
1223 applicationId = "cc.vectrum.code"
1324 minSdk = 29
1425 targetSdk = 37
15- versionCode = 1
16- versionName = "0.1.0"
26+ versionCode = desktopVersionCode
27+ versionName = desktopVersion
1728 }
1829
1930 buildFeatures { compose = true }
+16−15build.shView File
@@ -3,7 +3,7 @@
33 # build/vectrum-code plain binary
44 # build/Vectrum_Code-<version>-<arch>.AppImage
55 # and, with -a, a third:
6- # build/Vectrum_Code-<versionName>-<versionCode>.apk
6+ # build/Vectrum_Code-<version>.apk
77 #
88 # A binary only runs on the glibc it was linked against or a newer one, so by
99 # default it is built in an Ubuntu 24.04 container and linked against glibc
@@ -23,10 +23,12 @@
2323 # AppImage, the binary (and the APK with -a) and SHA256SUMS
2424 # (the first upload publishes the release). Each release
2525 # needs a new version.
26- # -a, --android also build the Android app (android/) as a release APK,
27- # with the versionCode and versionName that
28- # android/app/build.gradle.kts defines. Needs JDK 21 and
29- # the Android SDK (android/local.properties or ANDROID_HOME)
26+ # -a, --android also build the Android app (android/) as a release APK.
27+ # It has the desktop version as its versionName, and
28+ # versionCode major*1000000 + minor*1000 + patch (0.1.9 →
29+ # 1009); android/app/build.gradle.kts reads Cargo.toml.
30+ # Needs JDK 21 and the Android SDK (android/local.properties
31+ # or ANDROID_HOME)
3032 # --native build with the host toolchain instead of the container;
3133 # the binary then needs the host's glibc or newer
3234 # -h, --help show this
@@ -102,12 +104,7 @@ if (( ! NATIVE )); then
102104 fi
103105
104106 if (( ANDROID )); then
105- GRADLE_APP="$ROOT/android/app/build.gradle.kts"
106- [[ -f "$GRADLE_APP" ]] || die "No Android app at android/app/build.gradle.kts"
107- APK_CODE="$(sed -n 's/^ *versionCode *= *\([0-9][0-9]*\).*/\1/p' "$GRADLE_APP" | tail -n1)"
108- APK_VERSION="$(sed -n 's/^ *versionName *= *"\(.*\)".*/\1/p' "$GRADLE_APP" | tail -n1)"
109- [[ -n "$APK_CODE" && -n "$APK_VERSION" ]] ||
110- die "Couldn't read versionCode and versionName from android/app/build.gradle.kts"
107+ [[ -x "$ROOT/android/gradlew" ]] || die "No Android app at android/"
111108 command -v java >/dev/null || die "The Android build needs a JDK (21) on \$PATH or in JAVA_HOME"
112109 [[ -n "${ANDROID_HOME:-}${ANDROID_SDK_ROOT:-}" ]] || grep -qs '^sdk\.dir=' "$ROOT/android/local.properties" ||
113110 die "The Android build needs the SDK: set ANDROID_HOME or sdk.dir in android/local.properties"
@@ -258,11 +255,15 @@ log "AppImage: ${OUT#"$ROOT"/}"
258255
259256 # ── 5. Android ───────────────────────────────────────────────────────────────
260257 if (( ANDROID )); then
261- APK="$BUILD/${PRETTY// /_}-$APK_VERSION-$APK_CODE.apk"
262- log "Building the Android app $APK_VERSION (versionCode $APK_CODE, release)"
258+ APK="$BUILD/${PRETTY// /_}-$VERSION.apk"
259+ APK_OUT="$ROOT/android/app/build/outputs/apk/release"
260+ log "Building the Android app $VERSION (release)"
263261 (cd "$ROOT/android" && ./gradlew --quiet :app:assembleRelease)
264- install -m644 "$ROOT/android/app/build/outputs/apk/release/app-release.apk" "$APK"
265- log "APK: ${APK#"$ROOT"/}"
262+ APK_VERSION="$(sed -n 's/.*"versionName": *"\([^"]*\)".*/\1/p' "$APK_OUT/output-metadata.json")"
263+ APK_CODE="$(sed -n 's/.*"versionCode": *\([0-9]*\).*/\1/p' "$APK_OUT/output-metadata.json")"
264+ [[ "$APK_VERSION" == "$VERSION" ]] || die "The APK came out as version $APK_VERSION, not $VERSION"
265+ install -m644 "$APK_OUT/app-release.apk" "$APK"
266+ log "APK: ${APK#"$ROOT"/} (versionCode $APK_CODE)"
266267 fi
267268
268269 # ── 6. Release ───────────────────────────────────────────────────────────────