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:
parent
c5af978d14
commit
9d97b3c53d
11 changed files with 1440 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
173
scripts/build-monero-wallet-rpc-android.sh
Executable file
173
scripts/build-monero-wallet-rpc-android.sh
Executable file
|
|
@ -0,0 +1,173 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Reproduce the bundled `monero-wallet-rpc` for Android (arm64-v8a).
|
||||
#
|
||||
# This is the command behind `android/app/src/main/jniLibs/arm64-v8a/
|
||||
# libmonerowalletrpc.so` and `android/MONERO_BINARIES.md`. It is deliberately
|
||||
# NOT part of the CI path: building Monero's C++ tree for Android is a
|
||||
# ~30-45 min job on 12 cores and CI here runs on an arm64 Raspberry Pi. CI
|
||||
# re-verifies the committed blob's checksum instead (see
|
||||
# `scripts/build-android-local.sh`); this script is how that blob is produced
|
||||
# and how a reviewer re-derives it.
|
||||
#
|
||||
# Monero ships no Android binaries and no Android CMake preset, so this uses
|
||||
# upstream's own cross-compile path: `contrib/depends` (which builds boost,
|
||||
# openssl, libunbound, libzmq, libsodium, ncurses and readline for the target)
|
||||
# plus the toolchain.cmake it emits.
|
||||
#
|
||||
# Usage:
|
||||
# scripts/build-monero-wallet-rpc-android.sh [workdir]
|
||||
#
|
||||
# Output:
|
||||
# <workdir>/monero-src/build/aarch64-linux-android/release/bin/monero-wallet-rpc
|
||||
#
|
||||
# Requirements (all host-side): git, make, cmake 3.2x (NOT 4.x — see below),
|
||||
# unzip, curl, python3, a JDK-free C/C++ host toolchain (gcc/clang), ~15 GB free.
|
||||
set -euo pipefail
|
||||
|
||||
MONERO_TAG="${MONERO_TAG:-v0.18.4.4}"
|
||||
WORKDIR="${1:-${HOME}/.hermes/tmp/monero-src}"
|
||||
JOBS="${JOBS:-$(nproc)}"
|
||||
# NDK r17b is what `contrib/depends/packages/android_ndk.mk` pins; it downloads
|
||||
# and unpacks it itself. Nothing here uses the Gradle-side NDK.
|
||||
NDK_ABI_DIR="aarch64-linux-android"
|
||||
|
||||
root="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
cd "$root"
|
||||
|
||||
echo "==> monero $MONERO_TAG -> $WORKDIR ($JOBS jobs)"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 0. cmake 3.x. CMake 4.x removed the standalone-NDK-toolchain handling that
|
||||
# `contrib/depends`' generated toolchain.cmake relies on; with 4.x the
|
||||
# configure step picks the HOST clang and dies on `--target=` link flags.
|
||||
# ---------------------------------------------------------------------------
|
||||
CMAKE_BIN="${CMAKE_BIN:-cmake}"
|
||||
if ! "$CMAKE_BIN" --version | head -1 | grep -qE 'version 3\.'; then
|
||||
echo "==> host cmake is not 3.x; installing 3.22.6 into $WORKDIR/../cmakevenv"
|
||||
python3 -m venv "$WORKDIR/../cmakevenv" >/dev/null 2>&1 || true
|
||||
"$WORKDIR/../cmakevenv/bin/pip" install -q "cmake==3.22.6"
|
||||
CMAKE_BIN="$WORKDIR/../cmakevenv/bin/cmake"
|
||||
fi
|
||||
"$CMAKE_BIN" --version | head -1
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 1. Source, at the tag. Submodules are mandatory: the configure step refuses
|
||||
# to run without external/miniupnp (and randomx/rapidjson/supercop build).
|
||||
# ---------------------------------------------------------------------------
|
||||
if [ ! -d "$WORKDIR/.git" ]; then
|
||||
git clone --depth 1 --branch "$MONERO_TAG" \
|
||||
https://github.com/monero-project/monero.git "$WORKDIR"
|
||||
fi
|
||||
git -C "$WORKDIR" submodule update --init --force --depth 1
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 2. Host quirk: the NDK r17b standalone toolchain's prebuilt `clang60` is
|
||||
# linked against ncurses 5 (`libtinfo.so.5`). Debian bookworm, Arch and
|
||||
# everything else current ships ncurses 6 only, so the compiler refuses to
|
||||
# start with "error while loading shared libraries: libtinfo.so.5". ncurses
|
||||
# 6 is ABI-compatible for what clang uses terminfo for; a shim directory is
|
||||
# enough, and it is scoped to this build via LD_LIBRARY_PATH.
|
||||
# ---------------------------------------------------------------------------
|
||||
compat="$WORKDIR/../ndk17-compat"
|
||||
mkdir -p "$compat"
|
||||
if [ ! -e "$compat/libtinfo.so.5" ]; then
|
||||
for cand in /usr/lib/libtinfo.so.6 \
|
||||
/usr/lib/x86_64-linux-gnu/libtinfo.so.6 \
|
||||
/usr/lib64/libtinfo.so.6 \
|
||||
/lib/x86_64-linux-gnu/libtinfo.so.6; do
|
||||
if [ -e "$cand" ]; then
|
||||
ln -sf "$cand" "$compat/libtinfo.so.5"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
if [ ! -e "$compat/libtinfo.so.5" ]; then
|
||||
echo "!! no libtinfo.so.6 found to shim libtinfo.so.5; NDK r17b clang will not run" >&2
|
||||
exit 1
|
||||
fi
|
||||
export LD_LIBRARY_PATH="$compat${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
||||
|
||||
# The card's rule for this host: never build C in /tmp (16 GB tmpfs with a
|
||||
# per-user quota — "Disk quota exceeded" mid-build looks like a protocol bug).
|
||||
export TMPDIR="${TMPDIR:-$WORKDIR/../monero-build-tmp}"
|
||||
mkdir -p "$TMPDIR"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 3. The dependencies, cross-built for the target. ~20 min.
|
||||
# ---------------------------------------------------------------------------
|
||||
make -C "$WORKDIR/contrib/depends" HOST="$NDK_ABI_DIR" -j"$JOBS"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 3b. The toolchain.cmake depends emits sets
|
||||
# SET(CMAKE_FIND_ROOT_PATH <prefix> /usr)
|
||||
# and /usr is the HOST. `CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY` does not
|
||||
# save you: /usr is a root, so `find_library()` happily returns host
|
||||
# libraries. That bites twice in this tree:
|
||||
# * monero's optional zmq extras (pgm, norm, gssapi_krb5, protolib, bsd,
|
||||
# md, protokit) get host paths appended to ZMQ_LIB, and the final link
|
||||
# dies with `/usr/lib/libpgm.so: error adding symbols: File in wrong
|
||||
# format` — a host x86-64 .so in an aarch64 link line;
|
||||
# * `find_package(HIDAPI)` succeeds against the host hidapi, defines
|
||||
# HAVE_HIDAPI, and src/device then fails to compile `hidapi/hidapi.h`.
|
||||
# Nothing under /usr is a valid Android target library, so drop it. This is
|
||||
# also what upstream's `make depends target=aarch64-linux-android` silently
|
||||
# relies on: it only works on a build host that happens to have none of
|
||||
# these installed.
|
||||
# ---------------------------------------------------------------------------
|
||||
prefix="$WORKDIR/contrib/depends/$NDK_ABI_DIR"
|
||||
tc="$prefix/share/toolchain.cmake"
|
||||
cp "$tc" "$tc.orig"
|
||||
sed -i -E "s|^SET\(CMAKE_FIND_ROOT_PATH .*|SET(CMAKE_FIND_ROOT_PATH ${prefix})|" "$tc"
|
||||
grep -qF "SET(CMAKE_FIND_ROOT_PATH ${prefix})" "$tc" \
|
||||
|| { echo "could not pin CMAKE_FIND_ROOT_PATH in $tc" >&2; exit 1; }
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 4. Configure with the toolchain depends just emitted, then build ONLY the
|
||||
# wallet RPC. The CMake target is `wallet_rpc_server`; the binary it emits is
|
||||
# `monero-wallet-rpc`. (`make monero-wallet-rpc` is not a target and fails
|
||||
# with "No rule to make target".)
|
||||
# ---------------------------------------------------------------------------
|
||||
builddir="$WORKDIR/build/$NDK_ABI_DIR/release"
|
||||
rm -rf "$builddir"
|
||||
mkdir -p "$builddir"
|
||||
(
|
||||
cd "$builddir"
|
||||
# `-U` on the optional-library cache entries is belt-and-braces for a reused
|
||||
# build dir: a cache written before the toolchain patch still holds the host
|
||||
# paths, and a stale cache is invisible until the link step.
|
||||
"$CMAKE_BIN" \
|
||||
-DCMAKE_TOOLCHAIN_FILE="$tc" \
|
||||
-DBUILD_TESTS=OFF \
|
||||
-DBUILD_DOCUMENTATION=OFF \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-U PGM_LIBRARY -U NORM_LIBRARY -U GSSAPI_LIBRARY -U PROTOLIB_LIBRARY \
|
||||
-U SODIUM_LIBRARY -U BSD_LIBRARY -U MD_LIBRARY -U PROTOKIT_LIBRARY \
|
||||
-U ZMQ_LIB -U ZMQ_INCLUDE_PATH -U HIDAPI_LIBRARY -U HIDAPI_INCLUDE_DIR \
|
||||
"$WORKDIR"
|
||||
make wallet_rpc_server -j"$JOBS"
|
||||
)
|
||||
|
||||
bin="$builddir/bin/monero-wallet-rpc"
|
||||
[ -s "$bin" ] || { echo "missing $bin" >&2; exit 1; }
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 5. Strip with the target's own strip, then verify the shape.
|
||||
# ---------------------------------------------------------------------------
|
||||
strip_bin="$WORKDIR/contrib/depends/$NDK_ABI_DIR/native/bin/${NDK_ABI_DIR}-strip"
|
||||
[ -x "$strip_bin" ] && "$strip_bin" "$bin" || true
|
||||
|
||||
echo "==> $bin"
|
||||
file "$bin"
|
||||
wc -c "$bin"
|
||||
sha256sum "$bin"
|
||||
|
||||
echo
|
||||
echo "==> to package it into the APK:"
|
||||
echo " cp '$bin' android/app/src/main/jniLibs/arm64-v8a/libmonerowalletrpc.so"
|
||||
echo " # then update android/monero-binaries.sha256 and android/MONERO_BINARIES.md"
|
||||
echo
|
||||
echo "NOTE: a Monero build is not bit-reproducible (build paths and timestamps"
|
||||
echo " land in the binary), so a fresh run will NOT match the committed"
|
||||
echo " sha256. That hash is a provenance record of the shipped blob and the"
|
||||
echo " thing CI verifies — not a reproducible-build assertion."
|
||||
Loading…
Reference in a new issue