168 lines
8.5 KiB
Markdown
168 lines
8.5 KiB
Markdown
|
|
# 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:
|
||
|
|
|
||
|
|
```bash
|
||
|
|
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.
|