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>
Showing 1 changed file with 39 additions and 4 deletions.
| @@ -2,6 +2,8 @@ | ||
| 2 | 2 | # Builds Vectrum Code in release mode and writes two artifacts to ./build: |
| 3 | 3 | # build/vectrum-code plain binary |
| 4 | 4 | # build/Vectrum_Code-<version>-<arch>.AppImage |
| 5 | + # and, with -a, a third: | |
| 6 | + # build/Vectrum_Code-<versionName>-<versionCode>.apk | |
| 5 | 7 | # |
| 6 | 8 | # A binary only runs on the glibc it was linked against or a newer one, so by |
| 7 | 9 | # default it is built in an Ubuntu 24.04 container and linked against glibc |
| @@ -18,8 +20,13 @@ | ||
| 18 | 20 | # and Cargo.lock and commits them as "Version X" |
| 19 | 21 | # -r, --release then publish the build as a release on Vectrum: tag the |
| 20 | 22 | # 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) | |
| 23 | 30 | # --native build with the host toolchain instead of the container; |
| 24 | 31 | # the binary then needs the host's glibc or newer |
| 25 | 32 | # -h, --help show this |
| @@ -36,10 +43,12 @@ die() { printf '\033[1;31mxx\033[0m %s\n' "$*" >&2; exit 1; } | ||
| 36 | 43 | |
| 37 | 44 | RELEASE=0 |
| 38 | 45 | NATIVE=0 |
| 46 | + ANDROID=0 | |
| 39 | 47 | NEW_VERSION="" |
| 40 | 48 | while (( $# )); do |
| 41 | 49 | case "$1" in |
| 42 | 50 | -r|--release) RELEASE=1 ;; |
| 51 | + -a|--android) ANDROID=1 ;; | |
| 43 | 52 | --native) NATIVE=1 ;; |
| 44 | 53 | -v|--version) |
| 45 | 54 | [[ $# -ge 2 ]] || die "$1 needs a version, like $1 0.1.2" |
| @@ -92,6 +101,18 @@ if (( ! NATIVE )); then | ||
| 92 | 101 | die "Can't reach Docker as ${DOCKER[*]}: start it, join the docker group, set DOCKER=\"sudo docker\", or use --native" |
| 93 | 102 | fi |
| 94 | 103 | |
| 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 | + | |
| 95 | 116 | if (( RELEASE )); then |
| 96 | 117 | SERVER="${VECTRUM_URL:-https://vectrum.cc}" |
| 97 | 118 | SERVER="${SERVER%/}" |
| @@ -235,13 +256,27 @@ rm -rf "$APPDIR" | ||
| 235 | 256 | |
| 236 | 257 | log "AppImage: ${OUT#"$ROOT"/}" |
| 237 | 258 | |
| 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 ─────────────────────────────────────────────────────────────── | |
| 239 | 269 | if (( RELEASE )); then |
| 240 | 270 | STAGE="$BUILD/release-$TAG" |
| 241 | 271 | rm -rf "$STAGE" |
| 242 | 272 | mkdir -p "$STAGE" |
| 243 | 273 | cp "$OUT" "$STAGE/" |
| 244 | 274 | 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 | |
| 245 | 280 | (cd "$STAGE" && sha256sum -- * > SHA256SUMS) |
| 246 | 281 | |
| 247 | 282 | if [[ -z "$LOCAL_TAG" ]]; then |
| @@ -253,7 +288,7 @@ if (( RELEASE )); then | ||
| 253 | 288 | fi |
| 254 | 289 | |
| 255 | 290 | # 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 | |
| 257 | 292 | file="$STAGE/$name" |
| 258 | 293 | log "Uploading $name" |
| 259 | 294 | # The token goes in through a file descriptor, so it never shows in ps. |