name: android-ci # Android changes had no CI at all: ci.yml's path allowlist (src/**, crates/**, # tests/**, Cargo.toml, Cargo.lock, ci.yml) never matches android/**, and # android-release.yml is dispatch/tag-driven — so an android-only PR ran zero # jobs and merged on an empty check list. This is the android side of CI. # # It builds the same gradle targets the release builds through the same script # android-release.yml calls (scripts/build-android-local.sh): `:sdk:assembleRelease` # + `:app:assembleRelease`, Rust for aarch64-linux-android via cargo-ndk, UniFFI # bindings, APK packaging with the .so. The only difference from a release is # signing: ONIONWIRE_REQUIRE_RELEASE_KEY=false and no release keystore, so # Gradle falls back to the debug key. Nothing here is signed for release, # nothing is published, no tag is touched. # # Why a separate workflow instead of android/** added to ci.yml: the only way # to keep the Rust jobs from running on android-only diffs is job-level change # detection, and a gate that mis-detects hands out a green check for a suite # that never ran. Here the runner's own paths filter decides — same mechanism # ci.yml already uses. on: push: branches: [main] paths: - "android/**" - "crates/**" - "src/**" - "Cargo.toml" - "Cargo.lock" - "scripts/build-android-local.sh" - ".forgejo/workflows/android-ci.yml" pull_request: paths: - "android/**" - "crates/**" - "src/**" - "Cargo.toml" - "Cargo.lock" - "scripts/build-android-local.sh" - ".forgejo/workflows/android-ci.yml" workflow_dispatch: # Deliberately the SAME group and the SAME volumes as android-release.yml: the # APK build is ~9 min with warm volumes (SDK/NDK, cargo registry, cargo target, # Gradle cache) and a cold copy of those is over a gigabyte of downloads per # runner. Serializing the two workflows by group name is what keeps them off # each other's volumes. concurrency: group: onionwire-android-release-v2 cancel-in-progress: false env: CARGO_TERM_COLOR: never CARGO_BUILD_JOBS: "1" ONIONWIRE_ANDROID_ABI: arm64-v8a ANDROID_IMAGE: debian:bookworm ANDROID_CMDLINE_TOOLS_URL: https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip # Not the workspace MSRV (`rust-version = "1.91"`, and `ci.yml` stays on it): the # cuprated graph needs more. `tapes` (a Cuprate dependency) calls # `VecDeque::pop_front_if`, stable only from **1.93**, so 1.91 dies with # `error[E0658]: use of unstable library feature 'vec_deque_pop_if'` — 15 minutes # into the Android job, after 400-odd crates, in a dependency this repo cannot # patch. 1.98 is the stable release this graph is built and tested with on the dev # machine. Bumping `ci.yml` too is a separate decision (it would move the MSRV for # the whole workspace) and is not this workflow's to make. RUST_TOOLCHAIN: "1.98" DOCKER_STATIC_URL: https://download.docker.com/linux/static/stable/x86_64/docker-27.5.1.tgz # Distinct container prefix: run ids are per-workflow, so this workflow and # android-release.yml can both be holding a container named "-". BUILD_CONTAINER: onionwire-android-ci-${{ github.run_id }} SDK_VOLUME: onionwire-android-sdk CARGO_VOLUME: onionwire-android-cargo-registry TARGET_VOLUME: onionwire-android-target GRADLE_VOLUME: onionwire-android-gradle jobs: android: runs-on: docker-amd64 timeout-minutes: 120 steps: - name: Checkout uses: https://code.forgejo.org/actions/checkout@v4 with: fetch-depth: 0 - name: Record runner resources run: | set -euo pipefail cd "${GITHUB_WORKSPACE}" echo "workspace=$GITHUB_WORKSPACE hostname=$(hostname) arch=$(uname -m)" nproc || true free -h || true df -h || true ls -l /var/run/docker.sock || true - name: Ensure docker CLI run: | set -euo pipefail if ! command -v docker >/dev/null 2>&1; then echo "docker CLI missing in job image; fetching static client" curl -fsSL "$DOCKER_STATIC_URL" -o /tmp/docker.tgz tar -xzf /tmp/docker.tgz -C /tmp install -m 755 /tmp/docker/docker /usr/local/bin/docker fi export DOCKER_HOST="${DOCKER_HOST:-unix:///var/run/docker.sock}" docker version docker info >/tmp/docker-info.txt grep -E 'Server Version|Operating System|Total Memory|Name' /tmp/docker-info.txt || true - name: Build APK + AAR (debug-signed) in bookworm container id: build run: | set -euo pipefail cd "${GITHUB_WORKSPACE}" export DOCKER_HOST="${DOCKER_HOST:-unix:///var/run/docker.sock}" start=$(date +%s) cat > .ci-android-verify.sh <<'INNER' #!/usr/bin/env bash set -euo pipefail export DEBIAN_FRONTEND=noninteractive apt-get update # `cmake` is for RandomX, the C++ half of the in-process chain daemon: # without it `randomx-rs`'s build script panics with "failed to execute # command: No such file or directory … is `cmake` not installed?" and the # Gradle task dies on "cargo finished with non-zero exit value 101". apt-get install -y --no-install-recommends \ openjdk-17-jdk-headless python3 unzip curl ca-certificates file build-essential pkg-config git \ cmake if [ ! -x /opt/android-sdk/cmdline-tools/latest/bin/sdkmanager ]; then mkdir -p /opt/android-sdk/cmdline-tools curl -fsSL "$ANDROID_CMDLINE_TOOLS_URL" -o /tmp/cmdline-tools.zip rm -rf /tmp/cmdline-tools unzip -q /tmp/cmdline-tools.zip -d /tmp/cmdline-tools mkdir -p /opt/android-sdk/cmdline-tools/latest cp -a /tmp/cmdline-tools/cmdline-tools/. /opt/android-sdk/cmdline-tools/latest/ fi yes | /opt/android-sdk/cmdline-tools/latest/bin/sdkmanager --sdk_root=/opt/android-sdk --licenses >/tmp/sdk-licenses.log || true /opt/android-sdk/cmdline-tools/latest/bin/sdkmanager --sdk_root=/opt/android-sdk \ "platform-tools" "platforms;android-36" "build-tools;36.0.0" "ndk;28.2.13676358" test -d /opt/android-sdk/ndk/28.2.13676358 export ANDROID_HOME=/opt/android-sdk ANDROID_SDK_ROOT=/opt/android-sdk export ANDROID_NDK_HOME=/opt/android-sdk/ndk/28.2.13676358 export PATH="$ANDROID_HOME/build-tools/36.0.0:$ANDROID_HOME/platform-tools:$PATH" if [ ! -x /cargo/bin/rustup ]; then curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain "$RUST_TOOLCHAIN" --no-modify-path --profile minimal fi export PATH="/cargo/bin:$PATH" rustup toolchain install "$RUST_TOOLCHAIN" rustup default "$RUST_TOOLCHAIN" rustup target add aarch64-linux-android command -v cargo-ndk >/dev/null || cargo install cargo-ndk --locked echo "=== toolchain ===" java -version rustc --version cargo ndk --version du -sh /opt/android-sdk /cargo /cargo-target /gradle || true # No keystore here on purpose: this is a verification build, not a # release build. The script warns that Gradle fell back to the debug # key; that warning is expected in this job. scripts/build-android-local.sh version="$(python3 - <<'PY' 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 '') PY )" abi="${ONIONWIRE_ANDROID_ABI:-arm64-v8a}" apk="dist/onionwire-$version-android-$abi.apk" aar="dist/onionwire-sdk-$version.aar" { echo "=== file ===" file "$apk" "$aar" echo "=== unzip lib ===" unzip -l "$apk" | grep -E 'lib/.+\.so' || true unzip -l "$apk" | grep "lib/$abi/libonionwire_sdk.so" # `unzip -l` shows the uncompressed size only; the *deflated* entry is # what the download actually costs, and it is not visible anywhere else # (v0.7.0's SDK lib was 33,481,336 B raw / 12,210,154 B deflated, which # is the ratio a reader wants when this one grows). echo "=== native lib entries (length / method / deflated) ===" unzip -v "$apk" | grep -E 'lib/.+\.so$' echo "=== in-process chain daemon (cuprate-daemon) is IN this APK ===" # The build log's "features=cuprate-daemon" line says the feature was # *requested*; this says it is *in the artifact*. `target_max_memory` is # a rodata literal from src/cuprate.rs's config TOML, compiled only under # `#[cfg(feature = "cuprate-daemon")]` — v0.7.0's libonionwire_sdk.so # contains zero occurrences of it (checked), so its presence is the # difference between a build that carries the daemon and one that only # claims to. A missing marker fails the job: an APK whose on-device node # can only fail is the regression this gate exists to catch. unzip -p "$apk" "lib/$abi/libonionwire_sdk.so" > /tmp/libonionwire_sdk.so # `grep -c`, deliberately not `grep -q`: under `set -o pipefail` a `-q` # match closes the pipe early, `strings` dies on SIGPIPE (141), and the # pipeline then reports failure even though the marker was there — this # gate failed its own green build once that way. marker="$(strings -a /tmp/libonionwire_sdk.so | grep -c 'target_max_memory' || true)" echo "target_max_memory occurrences: ${marker:-0}" if [ "${marker:-0}" -lt 1 ]; then echo "lib/$abi/libonionwire_sdk.so carries no cuprated config string: the cuprate-daemon feature is NOT in this APK" >&2 exit 1 fi echo "=== classes.dex + Compose entrypoints ===" unzip -l "$apk" | grep -E 'classes[0-9]*\.dex' | head -n3 echo "=== sha256 ===" # `sha256sum -c` proves each artifact matches the digest the build # recorded, but prints neither number. The digest *is* the artifact's # identity, and an APK is not byte-reproducible across machines, so it # cannot be derived from the tree afterwards — echo both. cat "dist/onionwire-$version-android-$abi.apk.sha256" "dist/onionwire-sdk-$version.aar.sha256" ( cd dist && sha256sum -c "onionwire-$version-android-$abi.apk.sha256" "onionwire-sdk-$version.aar.sha256" ) echo "=== apksigner (expect debug cert: this is a verification build) ===" apksigner verify --print-certs "$apk" | sed -n '1,6p' echo "=== aapt ===" aapt dump badging "$apk" | sed -n '1,20p' || true echo "=== sizes ===" wc -c "$apk" "$aar" # The cross-compile volume this build just grew. The cuprated graph is # ~152 crates plus a C++ RandomX build, so the number is the disk cost # of the feature on the runner, next to the wall clock above. echo "=== cargo target volume (after this build) ===" du -sh /cargo-target 2>/dev/null || true du -sh /cargo-target/aarch64-linux-android/release 2>/dev/null || true } | tee dist/android-ci-verify.log INNER chmod +x .ci-android-verify.sh docker volume create "$SDK_VOLUME" >/dev/null docker volume create "$CARGO_VOLUME" >/dev/null docker volume create "$TARGET_VOLUME" >/dev/null docker volume create "$GRADLE_VOLUME" >/dev/null docker rm -f "$BUILD_CONTAINER" >/dev/null 2>&1 || true docker pull "$ANDROID_IMAGE" # 2 GB of Gradle heap, not 1: the only budget in this build that is close # is the single-use daemon's heap, which now has to package a 55 MB SDK # lib (plus RandomX's 1.1 MB) through AGP's in-daemon packaging. Run 414 # died in `:app:packageRelease` with the cause hidden inside # `PackageAndroidArtifact$IncrementalSplitterRunnable` — no "Caused by" # line, nothing in the log — so give it room instead of guessing again. # The runner has 15 GB and the job's peak RSS is ~3 GB. docker create --name "$BUILD_CONTAINER" -i \ -e CARGO_TERM_COLOR=never \ -e CARGO_BUILD_JOBS="$CARGO_BUILD_JOBS" \ -e CARGO_HOME=/cargo \ -e CARGO_TARGET_DIR=/cargo-target \ -e GRADLE_USER_HOME=/gradle \ -e ANDROID_HOME=/opt/android-sdk \ -e ANDROID_SDK_ROOT=/opt/android-sdk \ -e ANDROID_NDK_HOME=/opt/android-sdk/ndk/28.2.13676358 \ -e ONIONWIRE_ANDROID_ABI="$ONIONWIRE_ANDROID_ABI" \ -e ONIONWIRE_REQUIRE_RELEASE_KEY=false \ -e RUST_TOOLCHAIN="$RUST_TOOLCHAIN" \ -e ANDROID_CMDLINE_TOOLS_URL="$ANDROID_CMDLINE_TOOLS_URL" \ -e GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8" \ -v "$SDK_VOLUME":/opt/android-sdk \ -v "$CARGO_VOLUME":/cargo \ -v "$TARGET_VOLUME":/cargo-target \ -v "$GRADLE_VOLUME":/gradle \ -w /src \ "$ANDROID_IMAGE" \ bash -euxc 'mkdir -p /src && tar xzf - -C /src && cd /src && bash /src/.ci-android-verify.sh' tar czf - \ --exclude=./target --exclude=./.git --exclude=./.worktrees \ --exclude=./android/.gradle --exclude=./android/app/build \ --exclude=./android/sdk/build --exclude=./dist \ --exclude=./crates/onionwire-sdk/target \ . \ | docker start -a -i "$BUILD_CONTAINER" mkdir -p dist docker cp "$BUILD_CONTAINER:/src/dist/." dist/ end=$(date +%s) echo "build_wall_clock_seconds=$((end - start))" echo "wall_clock_seconds=$((end - start))" >> "$GITHUB_OUTPUT" docker rm -f "$BUILD_CONTAINER" >/dev/null || true ls -l dist/ - name: Verify artifacts run: | set -euo pipefail cd "${GITHUB_WORKSPACE}" abi="$ONIONWIRE_ANDROID_ABI" ls -l dist/ apk="$(ls dist/onionwire-*-android-$abi.apk)" aar="$(ls dist/onionwire-sdk-*.aar)" [ -s "$apk" ] || { echo "missing or empty $apk" >&2; exit 1; } [ -s "$aar" ] || { echo "missing or empty $aar" >&2; exit 1; } echo "apk=$apk bytes=$(wc -c < "$apk")" echo "aar=$aar bytes=$(wc -c < "$aar")" ( cd dist && sha256sum -c ./*.sha256 ) echo "=== android-ci-verify.log (from build container) ===" cat dist/android-ci-verify.log echo "=== resources after build ===" free -h || true df -h || true