Vectrum
Sign In

build.sh: -a/--android also builds the release APK

Reads versionCode and versionName from android/app/build.gradle.kts,
writes build/Vectrum_Code-<versionName>-<versionCode>.apk, and uploads it
with -r.

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

Showing 1 changed file with 39 additions and 4 deletions.

+39−4build.shView File
@@ -2,6 +2,8 @@
22 # Builds Vectrum Code in release mode and writes two artifacts to ./build:
33 # build/vectrum-code plain binary
44 # build/Vectrum_Code-<version>-<arch>.AppImage
5+ # and, with -a, a third:
6+ # build/Vectrum_Code-<versionName>-<versionCode>.apk
57 #
68 # A binary only runs on the glibc it was linked against or a newer one, so by
79 # default it is built in an Ubuntu 24.04 container and linked against glibc
@@ -18,8 +20,13 @@
1820 # and Cargo.lock and commits them as "Version X"
1921 # -r, --release then publish the build as a release on Vectrum: tag the
2022 # commit with the version, push the tag, and upload the
21- # AppImage, the binary and SHA256SUMS (the first upload
22- # publishes the release). Each release needs a new version.
23+ # AppImage, the binary (and the APK with -a) and SHA256SUMS
24+ # (the first upload publishes the release). Each release
25+ # 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)
2330 # --native build with the host toolchain instead of the container;
2431 # the binary then needs the host's glibc or newer
2532 # -h, --help show this
@@ -36,10 +43,12 @@ die() { printf '\033[1;31mxx\033[0m %s\n' "$*" >&2; exit 1; }
3643
3744 RELEASE=0
3845 NATIVE=0
46+ ANDROID=0
3947 NEW_VERSION=""
4048 while (( $# )); do
4149 case "$1" in
4250 -r|--release) RELEASE=1 ;;
51+ -a|--android) ANDROID=1 ;;
4352 --native) NATIVE=1 ;;
4453 -v|--version)
4554 [[ $# -ge 2 ]] || die "$1 needs a version, like $1 0.1.2"
@@ -92,6 +101,18 @@ if (( ! NATIVE )); then
92101 die "Can't reach Docker as ${DOCKER[*]}: start it, join the docker group, set DOCKER=\"sudo docker\", or use --native"
93102 fi
94103
104+ 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"
111+ command -v java >/dev/null || die "The Android build needs a JDK (21) on \$PATH or in JAVA_HOME"
112+ [[ -n "${ANDROID_HOME:-}${ANDROID_SDK_ROOT:-}" ]] || grep -qs '^sdk\.dir=' "$ROOT/android/local.properties" ||
113+ die "The Android build needs the SDK: set ANDROID_HOME or sdk.dir in android/local.properties"
114+ fi
115+
95116 if (( RELEASE )); then
96117 SERVER="${VECTRUM_URL:-https://vectrum.cc}"
97118 SERVER="${SERVER%/}"
@@ -235,13 +256,27 @@ rm -rf "$APPDIR"
235256
236257 log "AppImage: ${OUT#"$ROOT"/}"
237258
238- # ── 5. Release ───────────────────────────────────────────────────────────────
259+ # ── 5. Android ───────────────────────────────────────────────────────────────
260+ if (( ANDROID )); then
261+ APK="$BUILD/${PRETTY// /_}-$APK_VERSION-$APK_CODE.apk"
262+ log "Building the Android app $APK_VERSION (versionCode $APK_CODE, release)"
263+ (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"/}"
266+ fi
267+
268+ # ── 6. Release ───────────────────────────────────────────────────────────────
239269 if (( RELEASE )); then
240270 STAGE="$BUILD/release-$TAG"
241271 rm -rf "$STAGE"
242272 mkdir -p "$STAGE"
243273 cp "$OUT" "$STAGE/"
244274 cp "$BUILD/$NAME" "$STAGE/$NAME-$VERSION-$ARCH"
275+ UPLOADS=("$(basename "$OUT")" "$NAME-$VERSION-$ARCH")
276+ if (( ANDROID )); then
277+ cp "$APK" "$STAGE/"
278+ UPLOADS+=("$(basename "$APK")")
279+ fi
245280 (cd "$STAGE" && sha256sum -- * > SHA256SUMS)
246281
247282 if [[ -z "$LOCAL_TAG" ]]; then
@@ -253,7 +288,7 @@ if (( RELEASE )); then
253288 fi
254289
255290 # The checksums go last, so the release never shows them alone.
256- for name in "$(basename "$OUT")" "$NAME-$VERSION-$ARCH" SHA256SUMS; do
291+ for name in "${UPLOADS[@]}" SHA256SUMS; do
257292 file="$STAGE/$name"
258293 log "Uploading $name"
259294 # The token goes in through a file descriptor, so it never shows in ps.