onionwire/android/MONERO_BINARIES.md
apk-dev 0134396588
All checks were successful
android-ci / android (pull_request) Successful in 8m59s
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.
2026-09-18 10:20:08 -04:00

8.5 KiB

Bundled native executables (jniLibs)

The wallet screen starts an app-owned monero-wallet-rpc child (issue #107, src/wallet_child.rs). Monero ships no Android binaries, so this repository carries one, built here.

File in the tree android/app/src/main/jniLibs/arm64-v8a/libmonerowalletrpc.so
Bytes 19 954 224 (stripped)
sha256 d9126788030ecd1ccdb40c7764e66e9a14d158a147ad335b256f0577681b5ad4
Format ELF 64-bit LSB shared object, ARM aarch64, dynamically linked, interpreter /system/bin/linker64, for Android 21, built by NDK r17b
Needed libs libc.so, libm.so, libdl.so — everything else is static
Source https://github.com/monero-project/monero
Tag v0.18.4.4
Commit 516e5355a103a2bf0b7e10328ebcaa2945019445
Reproduce with scripts/build-monero-wallet-rpc-android.sh
Verified by android/monero-binaries.sha256, checked by scripts/build-android-local.sh on every build (local and CI)

Only arm64-v8a is built. -Ponionwire.abis=x86_64 produces an APK with no wallet binary in it — the screen says so (NO_WALLET_RPC_MESSAGE) instead of offering a Start that cannot work.

How it is built

scripts/build-monero-wallet-rpc-android.sh runs upstream's own Android cross-compile path — contrib/depends (boost, openssl, libunbound, libzmq, libsodium, ncurses, readline, libiconv, expat for aarch64-linux-android) plus the toolchain.cmake it emits — and then builds the single CMake target wallet_rpc_server. It takes ~40 min on 12 cores and needs ~15 GB of scratch space. It is not part of the CI path: CI here runs on a Raspberry Pi and the Gradle build is already ~9 minutes. CI verifies the committed bytes instead.

Four things about the build are worth writing down, because each one is a failure that looks like something else:

  1. CMake must be 3.x. contrib/depends emits a standalone-NDK-toolchain toolchain.cmake (CMAKE_ANDROID_STANDALONE_TOOLCHAIN). CMake 4.x no longer honours that, silently falls back to the host clang, and the configure step dies with ld.lld: cannot open /usr/lib/clang/.../libclang_rt.builtins.a. The script installs 3.22.6 into a venv when the host CMake is 4.x.

  2. The NDK r17b prebuilt clang60 needs libtinfo.so.5. android_ndk.mk pins NDK r17b and drives the long-removed make_standalone_toolchain.py (r17b still has it). Its clang60 binary is linked against ncurses 5; current distros ship ncurses 6 only, so every compile fails with error while loading shared libraries: libtinfo.so.5. A shim directory with libtinfo.so.5 -> libtinfo.so.6 on LD_LIBRARY_PATH fixes it. The script creates it.

  3. /usr is in CMAKE_FIND_ROOT_PATH, and /usr is the host. This is the one that costs the most time. CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY does not help: /usr is listed as a root, so find_library() returns host libraries. Two consequences in this tree:

    • find_package(HIDAPI) finds the host hidapi, defines HAVE_HIDAPI, and src/device then fails to compile hidapi/hidapi.h — the include dir it found is /usr/include/hidapi, so <hidapi/hidapi.h> resolves to /usr/include/hidapi/hidapi/hidapi.h.
    • Monero's optional zmq extras (pgm, norm, gssapi_krb5, protolib, bsd, md, protokit) are probed with find_library and appended to ZMQ_LIB, so the final link gets /usr/lib/libpgm.so — an x86-64 shared object in an aarch64 link line: error adding symbols: File in wrong format. libzmq.a does not actually reference openpgm.

    The script rewrites the generated toolchain.cmake to SET(CMAKE_FIND_ROOT_PATH <depends-prefix>). This is also why upstream's make depends target=aarch64-linux-android is not reproducible: it happens to work only on a build host with none of those libraries installed.

    A stale CMakeCache.txt keeps the host paths after the toolchain is fixed, and nothing complains until the link, so the script also passes -U PGM_LIBRARY -U GSSAPI_LIBRARY … and configures in a fresh build dir.

  4. The CMake target is wallet_rpc_server, not monero-wallet-rpc. The latter is the output name. make monero-wallet-rpc fails with No rule to make target.

Not bit-reproducible

Build paths and timestamps land in the binary, so a fresh run of the script will not reproduce the sha256 above. That hash is a provenance record of the shipped blob and the thing CI re-verifies — not a reproducible-build assertion. If you rebuild, update both android/monero-binaries.sha256 and this table in the same commit, and say what changed in the tag or the toolchain.

Why it is a jniLibs .so and not an asset

Since Android 10 (API 29) an app may not exec() a file in its own data directory: the SELinux policy carries no execute on app_data_file, so the familiar "ship it in assets/, copy it to filesDir, chmod 700" recipe is refused by the kernel regardless of the mode bits. The one directory Android hands out executable is ApplicationInfo.nativeLibraryDir, which the package manager populates from the APK's lib/<abi>/ entries at install time.

So the executable is named libmonerowalletrpc.so and shipped through jniLibs, and the path the core is handed is

<applicationInfo.nativeLibraryDir>/libmonerowalletrpc.so

resolved at runtime by wallet/WalletChildBinaries.kt. This only works with android:extractNativeLibs="true"; with the AGP 8 default (extractNativeLibs="false") the file stays inside the APK and there is nothing on disk to run. app/build.gradle.kts sets packaging.jniLibs.useLegacyPackaging = true for exactly that reason, and keepDebugSymbols for this one entry so AGP's strip pass cannot rewrite the bytes that CI verifies.

Cost: the release APK grows from ~9 MB to ~28 MB (the binary is deflate-stored at 6.9 MB) and installs ~20 MB into the app's native library directory.

arti is NOT bundled

WalletChild runs arti proxy -p <port> as the SOCKS child for a .onion daemon, and ChildConfig::validate requires a non-empty arti_bin for any chain source that is not receive-only. There is no arti executable in this build, and producing one (a standalone arti binary for aarch64-linux-android, from a crate the Rust side does not currently build as a bin) is a follow-up, not something this card could do without editing Cargo.toml/crates/**.

What the app does about it, honestly:

  • arti_bin is set to <nativeLibraryDir>/libarti.so — the path the binary would occupy. For a loopback or clearnet daemon the core never spawns it, so the value is inert. It is deliberately not set to a real binary: monero-wallet-rpc named as the SOCKS child would be spawned as the proxy the moment the user typed an .onion host.
  • The wallet screen refuses an .onion daemon while libarti.so is absent, and says why (ONION_NEEDS_ARTI_NOTICE) instead of letting the spawn fail.

So today: loopback and clearnet daemons work; .onion daemons do not.

Verification in CI

.forgejo/workflows/android-ci.yml builds the APK on every android/** PR and scripts/build-android-local.sh does the checking, so both CI jobs and local builds get it:

  1. before Gradle, sha256sum -c android/monero-binaries.sha256 against the committed blob;
  2. after packaging, unzip -p the lib/<abi>/libmonerowalletrpc.so entry out of the produced APK and compare its sha256 with the committed file. A mismatch fails the build — the bytes that ship are the bytes that were verified, not the bytes that were hoped for.

Not verified

The binary was not executed on a device or emulator. There is no arm64-v8a AVD on the build host (all three existing AVDs are x86_64), and no aarch64 sysroot to run it under qemu-user. What is proven: it cross-compiles, it is a valid aarch64 Android PIE executable, it packages into the APK with the expected bytes, and the Kotlin that drives it compiles. What is not: that monero-wallet-rpc starts, opens its wallet file and answers JSON-RPC under Android's runtime.

To close that gap:

sdkmanager "system-images;android-35;google_apis;arm64-v8a"
avdmanager create avd -n ow-arm64 -k "system-images;android-35;google_apis;arm64-v8a"
emulator -avd ow-arm64          # software-emulated on an x86_64 host: slow
adb install -r dist/onionwire-<version>-android-arm64-v8a.apk

then unlock the node, open Wallet, type a daemon as host:port, Save, and watch the status line for connecting → syncing → ready. A .onion daemon will stop at the arti notice above.