android: start/stop the monero-wallet-rpc child from WalletScreen, bundle the binary

Implements the Android half of issue #107. Stacked on `wt/t_8a8ff353`
(PR #108) because the UniFFI wallet-child surface is not on `main` yet.

Binary
------

`android/app/src/main/jniLibs/arm64-v8a/libmonerowalletrpc.so` is a real
`monero-wallet-rpc` cross-compiled for `aarch64-linux-android` from
monero-project/monero v0.18.4.4 (516e5355) via upstream's own
`contrib/depends` + toolchain.cmake path, then stripped with the target's own
strip. 19 954 224 bytes, sha256
d9126788030ecd1ccdb40c7764e66e9a14d158a147ad335b256f0577681b5ad4.

It ships through `jniLibs` and not as an asset on purpose: since API 29 the
kernel refuses `exec()` on a file in the app's data directory, so the only
executable directory an app has is `applicationInfo.nativeLibraryDir`, which
the package manager fills from `lib/<abi>/` at install time. That requires
`android:extractNativeLibs="true"` (`packaging.jniLibs.useLegacyPackaging`),
which `app/build.gradle.kts` now sets, plus `keepDebugSymbols` for this one
entry so AGP's strip pass cannot rewrite the bytes CI verifies.

`scripts/build-monero-wallet-rpc-android.sh` reproduces the build and
`android/MONERO_BINARIES.md` records the four host quirks that cost the most
time (CMake must be 3.x; NDK r17b clang60 needs a libtinfo.so.5 shim; the
generated toolchain.cmake puts the HOST `/usr` in CMAKE_FIND_ROOT_PATH, which
breaks the link with a host libpgm.so and defines HAVE_HIDAPI against host
headers; the CMake target is `wallet_rpc_server`, not `monero-wallet-rpc`).

CI re-verifies the blob rather than taking it on trust:
`scripts/build-android-local.sh` checks `android/monero-binaries.sha256` before
Gradle, and after packaging pulls `lib/<abi>/libmonerowalletrpc.so` back out of
the APK and compares its sha256 with the committed file.

`arti` is NOT bundled, so a `.onion` daemon cannot be started yet. The app says
that instead of pretending: `arti_bin` is set to the path the binary would
occupy, and the screen refuses an `.onion` daemon while it is absent.
Loopback and clearnet daemons work.

UI
--

`WalletScreen` gains a "wallet daemon" card above the existing
Create / Import / Invoice / Tip actions, which are untouched:

* a status line from `Wire::wallet_status()` rendered verbatim —
  `off` / `connecting` / `syncing` / `ready` / `exited` plus the core's
  chain-source label (`receive-only` / `local node` / `remote onion daemon` /
  `remote daemon`). A died child reads `exited`; it is never folded into `off`
  and never into `ready`;
* Start / Stop calling `start_wallet_child` / `stop_wallet_child` through
  `WireViewModel`, on `Dispatchers.IO` (the spawn is synchronous inside the node
  and the status read re-decrypts the sealed record);
* a `host:port` field that saves a remote daemon via `set_chain_source`, plus a
  Receive-only button;
* honest failure states instead of a spinner: no bundled binary, no chain
  source, a `.onion` daemon with no arti, or a start that failed — each gets its
  own sentence, and Start is disabled with the reason on screen.

`WireViewModel` owns the 2s wallet-child poller, the same way it owns the chat
poller, so leaving the wallet screen and coming back cannot stack a second loop.
`ui/WalletChildStatusText.kt` is the pure model (mirrors the
`ChatRowInput`/`OutboxRowInput` convention) and carries the state mapping, the
status line and the Start/Stop gates; `WalletChildStatusTextTest` covers them on
the JVM.

Verified
--------

`./gradlew :app:testDebugUnitTest` passes, `scripts/build-android-local.sh`
produces `dist/onionwire-0.1.0-android-arm64-v8a.apk` (27 884 277 bytes,
versionName 0.1.0 / versionCode 100) with
`lib/arm64-v8a/libmonerowalletrpc.so` inside it at the committed sha256, and
`extractNativeLibs="true"` in the merged release manifest.

NOT verified: the binary was never executed. The build host has no arm64-v8a
AVD (all three existing AVDs are x86_64) and no aarch64 sysroot for qemu-user,
so nothing here proves `monero-wallet-rpc` starts, opens its wallet file and
answers JSON-RPC under Android's runtime. `android/MONERO_BINARIES.md` says so
plainly and lists the emulator steps to close the gap.
This commit is contained in:
apk-dev 2026-09-18 10:19:18 -04:00
commit 9d97b3c53d
No known key found for this signature in database
11 changed files with 1440 additions and 1 deletions

View file

@ -45,6 +45,19 @@ fi
abi="${ONIONWIRE_ANDROID_ABI:-arm64-v8a}"
# ---------------------------------------------------------------------------
# Bundled native executables. CI must not take a committed blob on trust: the
# wallet screen runs `monero-wallet-rpc` straight out of the APK's `lib/<abi>/`,
# so a corrupted or swapped blob is a wallet-level problem rather than a
# build-level one. `android/monero-binaries.sha256` is the provenance record
# (see android/MONERO_BINARIES.md); this re-verifies it before every build, and
# again against the bytes that ended up inside the APK, below.
# ---------------------------------------------------------------------------
BINARY_MANIFEST="android/monero-binaries.sha256"
[ -f "$BINARY_MANIFEST" ] || { echo "missing $BINARY_MANIFEST" >&2; exit 1; }
echo "==> verifying bundled native executables against $BINARY_MANIFEST"
( cd android && sha256sum -c "$(basename "$BINARY_MANIFEST")" )
echo "==> android build: version $version (versionCode $ONIONWIRE_VERSION_CODE), abi $abi"
( cd android && "./gradlew" --no-daemon \
"-Ponionwire.abis=$abi" \
@ -77,6 +90,20 @@ done
echo "==> verify"
( cd dist && sha256sum -c ./*.sha256 )
file "$apk" "$aar"
# The bytes inside the shipped APK, not the bytes we hoped we copied. An AGP
# strip pass would rewrite `lib/<abi>/*.so` between jniLibs and the APK, which
# is why `app/build.gradle.kts` keeps debug symbols for this one entry.
echo "==> bundled wallet binary inside the APK"
bundled_sha="$(unzip -p "$apk" "lib/$abi/libmonerowalletrpc.so" | sha256sum | cut -d' ' -f1)"
committed_sha="$(sha256sum "android/app/src/main/jniLibs/$abi/libmonerowalletrpc.so" | cut -d' ' -f1)"
unzip -l "$apk" | grep "lib/$abi/" || true
echo "lib/$abi/libmonerowalletrpc.so sha256=$bundled_sha (committed $committed_sha)"
[ "$bundled_sha" = "$committed_sha" ] || {
echo "the APK's bundled binary does not match the committed blob" >&2
exit 1
}
ls -l "$apk" "$aar" "$apk.sha256" "$aar.sha256"
if [ -n "${PUBLISH_TAG:-}" ]; then