Merge pull request 'feat(android): auto-publish signed APK and AAR from CI' (#26) from wt/t_87d7245b into main
All checks were successful
ci / test (push) Successful in 3m8s

Reviewed-on: #26
This commit is contained in:
sirius 2026-09-12 04:59:41 +00:00
commit 4a248f5b73
4 changed files with 420 additions and 26 deletions

View file

@ -1,31 +1,55 @@
#!/usr/bin/env bash
# Build the Android artifacts on this host and publish them to a Forgejo
# release. There is no Android toolchain in CI: .forgejo/workflows/release.yml
# runs on an aarch64 Linux container and cannot produce an APK. This is the
# Android path, exactly like scripts/build-release-local.sh is the x86_64 path
# for the Linux binary.
# Build the Android artifacts on this host. Offline fallback for
# .forgejo/workflows/android-release.yml (which builds on docker-amd64).
#
# Usage:
# scripts/build-android-local.sh [version] # build + checksums only
# PUBLISH_TAG=v0.3.0 scripts/build-android-local.sh # also upload
# PUBLISH_TAG=v0.1.0 scripts/build-android-local.sh # also upload
#
# Requires: ANDROID_HOME (or android/local.properties), an installed NDK, the
# Rust android targets, cargo-ndk, JDK 17+, and a working `cargo` on PATH.
# Does not create or push tags: creating the tag is a human decision.
# Does not create or push tags: CI owns tag creation. This script only uploads
# when PUBLISH_TAG is set.
#
# Signing: if ~/.android/onionwire-release.env exists it is sourced so local
# and CI APKs share the repo-owned keystore. Without it, Gradle falls back to
# the debug keystore and warns. Never commit a keystore or password.
set -euo pipefail
root="$(cd "$(dirname "$0")/.." && pwd)"
cd "$root"
version="${1:-$(sed -n 's/.*versionName = "\(.*\)".*/\1/p' android/app/build.gradle.kts | head -1)}"
if [ -f "$HOME/.android/onionwire-release.env" ]; then
# shellcheck disable=SC1091
set -a
# shellcheck disable=SC1090
source "$HOME/.android/onionwire-release.env"
set +a
fi
# Arg wins; otherwise the committed Gradle default (today: 0.1.0).
version="${1:-}"
if [ -z "$version" ]; then
version="$(python3 -c "
import re, pathlib
t = pathlib.Path('android/app/build.gradle.kts').read_text()
m = re.search(r'versionName\\s*=.*?:\\s*\"([^\"]+)\"', t)
print(m.group(1) if m else '')
")"
fi
[ -n "$version" ] || { echo "could not determine version" >&2; exit 1; }
abi="${ONIONWIRE_ANDROID_ABI:-arm64-v8a}"
gradlew="$root/android/gradlew"
if [ -z "${ONIONWIRE_VERSION_CODE:-}" ]; then
ONIONWIRE_VERSION_CODE="$(python3 -c "m,n,p=map(int,'$version'.split('.')); print(m*10000+n*100+p)")"
fi
echo "==> android build: version $version, abi $abi"
abi="${ONIONWIRE_ANDROID_ABI:-arm64-v8a}"
echo "==> android build: version $version (versionCode $ONIONWIRE_VERSION_CODE), abi $abi"
( cd android && "./gradlew" --no-daemon \
"-Ponionwire.abis=$abi" \
"-Ponionwire.versionName=$version" \
"-Ponionwire.versionCode=$ONIONWIRE_VERSION_CODE" \
:sdk:assembleRelease :app:assembleRelease )
mkdir -p dist