ci(android): replace cargo-apk with cargo-ndk + manual APK assembly
cargo-apk 0.10 and its fork cargo-apk2 both failed to discover the installed Android platform in this Gitea runner, despite ANDROID_HOME, platforms;android-34, build-tools, and NDK all being present, readable, and pointed at correctly. We never isolated whether the bug is in the shared ndk-build crate's discovery logic or in the runner's env-var propagation through cargo subcommand exec, so this commit stops fighting either tool and assembles the APK from explicit toolchain steps instead: cargo ndk -> per-ABI .so files aapt2 compile/link -> manifest + resources -> base APK zip -> bundle native libs into lib/<abi>/ zipalign -> 4-byte alignment apksigner -> v2/v3 signing (debug keystore for CI, real for release) The pipeline lives in scripts/build_android_apk.sh so it's reproducible locally (same env vars, same commands). AndroidManifest.xml is now checked in under solitaire_app/android/ and mirrors what cargo-apk would have generated from [package.metadata.android] — keep them in sync if either is changed. Local `cargo apk build` still works on developer machines where cargo-apk is happy; CI just stops depending on it. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ env:
|
||||
ANDROID_SDK: /opt/android-sdk
|
||||
NDK_VERSION: "25.2.9519653"
|
||||
BUILD_TOOLS_VERSION: "34.0.0"
|
||||
PLATFORM: "android-34"
|
||||
|
||||
jobs:
|
||||
build-apk:
|
||||
@@ -32,7 +33,7 @@ jobs:
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y openjdk-17-jdk-headless unzip
|
||||
sudo apt-get install -y openjdk-17-jdk-headless unzip zip
|
||||
|
||||
# ── Android SDK (shared cache key with release workflow) ──────────
|
||||
- name: Cache Android SDK
|
||||
@@ -56,7 +57,7 @@ jobs:
|
||||
sudo ${{ env.ANDROID_SDK }}/cmdline-tools/latest/bin/sdkmanager \
|
||||
--sdk_root=${{ env.ANDROID_SDK }} \
|
||||
"build-tools;${{ env.BUILD_TOOLS_VERSION }}" \
|
||||
"platforms;android-34" \
|
||||
"platforms;${{ env.PLATFORM }}" \
|
||||
"ndk;${{ env.NDK_VERSION }}"
|
||||
|
||||
# ── Rust toolchain ─────────────────────────────────────────────────
|
||||
@@ -84,15 +85,12 @@ jobs:
|
||||
key: cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: cargo-registry-
|
||||
|
||||
# cargo-apk2 is the maintained fork of cargo-apk; reads the same
|
||||
# `[package.metadata.android]` block. Cache key prefix `apk2-`
|
||||
# so we don't restore an old cargo-apk binary from the previous key.
|
||||
- name: Cache cargo-apk2 binary
|
||||
- name: Cache cargo-ndk binary
|
||||
uses: actions/cache@v4
|
||||
id: apk-tool-cache
|
||||
id: ndk-tool-cache
|
||||
with:
|
||||
path: ~/.cargo/bin/cargo-apk2
|
||||
key: apk2-${{ runner.os }}-stable
|
||||
path: ~/.cargo/bin/cargo-ndk
|
||||
key: cargo-ndk-${{ runner.os }}-stable
|
||||
|
||||
- name: Cache build artifacts
|
||||
uses: actions/cache@v4
|
||||
@@ -101,16 +99,19 @@ jobs:
|
||||
key: android-target-${{ hashFiles('**/Cargo.lock') }}-${{ github.sha }}
|
||||
restore-keys: android-target-${{ hashFiles('**/Cargo.lock') }}-
|
||||
|
||||
# ── Build ──────────────────────────────────────────────────────────
|
||||
- name: Install cargo-apk2
|
||||
if: steps.apk-tool-cache.outputs.cache-hit != 'true'
|
||||
run: cargo install cargo-apk2 --locked
|
||||
- name: Install cargo-ndk
|
||||
if: steps.ndk-tool-cache.outputs.cache-hit != 'true'
|
||||
run: cargo install cargo-ndk --locked
|
||||
|
||||
# ── Build APK ──────────────────────────────────────────────────────
|
||||
- name: Build debug APK
|
||||
run: |
|
||||
export ANDROID_HOME=${{ env.ANDROID_SDK }}
|
||||
export ANDROID_NDK_HOME=${{ env.ANDROID_SDK }}/ndk/${{ env.NDK_VERSION }}
|
||||
cargo apk2 build --package solitaire_app --lib
|
||||
env:
|
||||
ANDROID_HOME: ${{ env.ANDROID_SDK }}
|
||||
ANDROID_NDK_HOME: ${{ env.ANDROID_SDK }}/ndk/${{ env.NDK_VERSION }}
|
||||
BUILD_TOOLS_VERSION: ${{ env.BUILD_TOOLS_VERSION }}
|
||||
PLATFORM: ${{ env.PLATFORM }}
|
||||
PROFILE: debug
|
||||
run: ./scripts/build_android_apk.sh
|
||||
|
||||
# ── Artifact ───────────────────────────────────────────────────────
|
||||
- name: Upload APK
|
||||
|
||||
Reference in New Issue
Block a user