android: build the SDK with cuprate-daemon and offer the on-device node #113

Merged
sirius merged 5 commits from onionwire/t_f05be394-android-build-the-sdk-with-cuprate-daemo into main 2026-09-18 21:42:55 +00:00
Owner

What this does

Part 3 of "cuprated built in": the in-process chain daemon is now in the APK, and the wallet screen can pick it.

Stacked on the SDK card (#111). #111 merged into onionwire/t_04975420-…, a branch that was already merged into main, so its commit (64a1f29) is not on main — this branch therefore carries it. A recovery card is landing those two commits on main; once it does, this branch is rebased onto main and the diff below becomes android/**-only. Until then the PR diff includes the parent's crates/onionwire-sdk/**.

Build: the feature is on, for the Android target only

android/sdk/build.gradle.kts — cargoBuildAndroid now runs cargo ndk … build --release --lib --features cuprate-daemon. cargoHostLib / uniffiBindgen stay feature-free on purpose: the host cdylib exists only so uniffi-bindgen --library can dlopen it, and the UniFFI surface does not fork on a cargo feature.

Three things the link needs, each of which fails as something else:

  • libc++ + compiler-rt builtins explicitly. RandomX is C++ and its aarch64 JIT calls __clear_cache; randomx-rs links the NDK's stub libstdc++.a, so without -lc++_static -lc++abi the link dies on __cxa_allocate_exception. cargo ndk --link-builtins covers the builtins only, and -static-libstdc++ is ignored by NDK clang.
  • Per-ABI CARGO_TARGET_<TRIPLE>_RUSTFLAGS, not RUSTFLAGS — a global rustflags also applies to build scripts and proc macros, which are host-targeted, where -lc++_static breaks the link.
  • The linker is the NDK clang driver at the app's API level, named explicitly. The dev machines pin the API 21 wrapper for aarch64-linux-android in ~/.cargo/config.toml, and API 21 fails this link (pthread_atfork is API 23+). ANDROID_NDK is exported too, or cmake-rs aborts and randomx-rs's build script panics.

The task logs the feature it builds with, so the CI log carries the request and not just the task name:

cargo ndk build for arm64-v8a features=cuprate-daemon api=26 ndk=28.2.13676358

Wallet screen

  • Third chain source, On-device node (Cuprate), beside the daemon field and Receive-only. Stored as ChainChoice.InProcessCuprate with an empty monerod_datadir, which the SDK resolves to $ONIONWIRE_HOME/chain — Kotlin never invents an absolute path. Save daemon / Receive-only / Start / Stop are untouched.
  • Status line grows · node <word> from WalletChildStatus.node_state for this source only, and an unrecognised word is never rendered as ready.
  • Storage honesty: the free space on the filesystem the fjall store grows into, shown before the user commits, and Start refused below a 3 GiB floor or when that filesystem cannot be read. The floor is a floor, not a sync estimate — WalletChildStatus has no size field and Cuprate's restricted RPC reports a hardcoded 5 GiB database_size placeholder, so a number taken from the node would be fiction.
  • Pre-production warning above Start, one sentence (quoted user book, testnet only, Cuprate issue #278), assertable in WalletChildStatusTextTest. Opt-in, never a default.
  • NO_WALLET_RPC_MESSAGE and ONION_NEEDS_ARTI_NOTICE still gate Start: Cuprate has no wallet layer, so monero-wallet-rpc stays a child, and an in-process node does not bundle arti.
  • No sync height, stated rather than papered over: the core keeps chain_height() internally but does not expose it over UniFFI, so the screen does not show a number it cannot get.

CI gate: in the artifact, not merely requested

android-ci.yml extracts lib/<abi>/libonionwire_sdk.so from the built APK and fails the job unless it contains target_max_memory — a rodata literal from src/cuprate.rs's config TOML, compiled only under #[cfg(feature = "cuprate-daemon")]. Negative control: v0.7.0's shipped .so has zero occurrences of it (and of randomx / cuprated).

Local numbers (this machine, 16 cores, sanity check — CI builds the APK)

v0.7.0 this branch
APK 28,016,993 B 34,447,502 B
libonionwire_sdk.so 33,481,336 B / 12,210,154 deflated 55,465,936 B / 18,246,997 deflated
new — lib/arm64-v8a/librandomx_rs-<hash>.so 1,122,296 B / 387,996 deflated

librandomx_rs-<hash>.so is not a load-time dependency: readelf -d libonionwire_sdk.so lists liblog.so and nothing else, and RandomX is statically inside the SDK's .so. cargo-ndk copies every cdylib in the target directory, and randomx-rs also builds one; it is left in place rather than filtered out (see android/CUPRATE_DAEMON.md).

:app:testDebugUnitTest — 98 tests, 0 failures. scripts/build-android-local.sh — exit 0, APK + AAR checksums verified.

Not verified

The daemon was not run on a device or emulator: there is no arm64-v8a AVD on the build host and no aarch64 Android sysroot for qemu-user. Proven: it cross-compiles and links against the NDK C++ runtime, the feature is in the shipped .so, the artifact packages, the Kotlin compiles and its unit tests pass. Not proven: that cuprated starts, opens its fjall store and answers on loopback under Android's runtime.

Docs: android/CUPRATE_DAEMON.md (new), android/MONERO_BINARIES.md (pointer).

## What this does Part 3 of "cuprated built in": the in-process chain daemon is now **in the APK**, and the wallet screen can pick it. Stacked on the SDK card (#111). #111 merged into `onionwire/t_04975420-…`, a branch that was already merged into `main`, so its commit (`64a1f29`) is **not** on `main` — this branch therefore carries it. A recovery card is landing those two commits on `main`; once it does, this branch is rebased onto `main` and the diff below becomes `android/**`-only. Until then the PR diff includes the parent's `crates/onionwire-sdk/**`. ## Build: the feature is on, for the Android target only `android/sdk/build.gradle.kts` — `cargoBuildAndroid` now runs `cargo ndk … build --release --lib --features cuprate-daemon`. `cargoHostLib` / `uniffiBindgen` stay feature-free on purpose: the host cdylib exists only so `uniffi-bindgen --library` can dlopen it, and the UniFFI surface does not fork on a cargo feature. Three things the link needs, each of which fails as something else: - **libc++ + compiler-rt builtins explicitly.** RandomX is C++ and its aarch64 JIT calls `__clear_cache`; `randomx-rs` links the NDK's *stub* `libstdc++.a`, so without `-lc++_static -lc++abi` the link dies on `__cxa_allocate_exception`. `cargo ndk --link-builtins` covers the builtins only, and `-static-libstdc++` is ignored by NDK clang. - **Per-ABI `CARGO_TARGET_<TRIPLE>_RUSTFLAGS`, not `RUSTFLAGS`** — a global rustflags also applies to build scripts and proc macros, which are host-targeted, where `-lc++_static` breaks the link. - **The linker is the NDK clang driver at the app's API level, named explicitly.** The dev machines pin the API 21 wrapper for `aarch64-linux-android` in `~/.cargo/config.toml`, and API 21 fails this link (`pthread_atfork` is API 23+). `ANDROID_NDK` is exported too, or `cmake-rs` aborts and `randomx-rs`'s build script panics. The task logs the feature it builds with, so the CI log carries the request and not just the task name: ``` cargo ndk build for arm64-v8a features=cuprate-daemon api=26 ndk=28.2.13676358 ``` ## Wallet screen - Third chain source, **On-device node (Cuprate)**, beside the daemon field and Receive-only. Stored as `ChainChoice.InProcessCuprate` with an **empty** `monerod_datadir`, which the SDK resolves to `$ONIONWIRE_HOME/chain` — Kotlin never invents an absolute path. Save daemon / Receive-only / Start / Stop are untouched. - Status line grows `· node <word>` from `WalletChildStatus.node_state` **for this source only**, and an unrecognised word is never rendered as ready. - **Storage honesty:** the free space on the filesystem the fjall store grows into, shown before the user commits, and Start refused below a 3 GiB floor or when that filesystem cannot be read. The floor is a floor, not a sync estimate — `WalletChildStatus` has no size field and Cuprate's restricted RPC reports a hardcoded 5 GiB `database_size` placeholder, so a number taken from the node would be fiction. - **Pre-production warning above Start**, one sentence (quoted user book, testnet only, Cuprate issue #278), assertable in `WalletChildStatusTextTest`. Opt-in, never a default. - `NO_WALLET_RPC_MESSAGE` and `ONION_NEEDS_ARTI_NOTICE` still gate Start: Cuprate has no wallet layer, so `monero-wallet-rpc` stays a child, and an in-process node does not bundle `arti`. - **No sync height**, stated rather than papered over: the core keeps `chain_height()` internally but does not expose it over UniFFI, so the screen does not show a number it cannot get. ## CI gate: in the artifact, not merely requested `android-ci.yml` extracts `lib/<abi>/libonionwire_sdk.so` from the built APK and **fails the job** unless it contains `target_max_memory` — a rodata literal from `src/cuprate.rs`'s config TOML, compiled only under `#[cfg(feature = "cuprate-daemon")]`. Negative control: v0.7.0's shipped `.so` has **zero** occurrences of it (and of `randomx` / `cuprated`). ## Local numbers (this machine, 16 cores, sanity check — CI builds the APK) | | v0.7.0 | this branch | |---|---|---| | APK | 28,016,993 B | 34,447,502 B | | `libonionwire_sdk.so` | 33,481,336 B / 12,210,154 deflated | 55,465,936 B / 18,246,997 deflated | | new | — | `lib/arm64-v8a/librandomx_rs-<hash>.so` 1,122,296 B / 387,996 deflated | `librandomx_rs-<hash>.so` is **not** a load-time dependency: `readelf -d libonionwire_sdk.so` lists `liblog.so` and nothing else, and RandomX is statically inside the SDK's `.so`. `cargo-ndk` copies every cdylib in the target directory, and `randomx-rs` also builds one; it is left in place rather than filtered out (see `android/CUPRATE_DAEMON.md`). `:app:testDebugUnitTest` — 98 tests, 0 failures. `scripts/build-android-local.sh` — exit 0, APK + AAR checksums verified. ## Not verified The daemon was **not** run on a device or emulator: there is no `arm64-v8a` AVD on the build host and no aarch64 Android sysroot for `qemu-user`. Proven: it cross-compiles and links against the NDK C++ runtime, the feature is in the shipped `.so`, the artifact packages, the Kotlin compiles and its unit tests pass. Not proven: that `cuprated` starts, opens its fjall store and answers on loopback under Android's runtime. Docs: `android/CUPRATE_DAEMON.md` (new), `android/MONERO_BINARIES.md` (pointer).
sdk: expose the on-device Cuprate chain source (choice, lifecycle, node status)
All checks were successful
ci / test (pull_request) Successful in 5m8s
ci / sdk (pull_request) Successful in 1m12s
android-ci / android (pull_request) Successful in 9m43s
ci / fuzz (pull_request) Successful in 4m41s
64a1f29e9e
ChainChoice gains InProcessCuprate, the SDK passes the core's cuprate-daemon
feature through as its own, and an empty monerod_datadir for that kind resolves
to $ONIONWIRE_HOME/chain so Kotlin never invents a path. wallet_status now
carries chain_in_process / node_available / node_state beside the core's five
state words; no second state machine, no timer, no env var.

start/stop stay the core's pass-through: one call launches the node and the
wallet child, one stops both, both idempotent.
Reviewed-on: #111
android: build the SDK with cuprate-daemon and offer the on-device node
Some checks failed
ci / test (pull_request) Successful in 5m3s
ci / sdk (pull_request) Successful in 1m6s
ci / fuzz (pull_request) Successful in 4m45s
android-ci / android (pull_request) Failing after 13m57s
f9f2055f70
Part 3 of "cuprated built in": the chain daemon now ships inside the APK and the
wallet screen can pick it.

Build (android/sdk/build.gradle.kts)
- `cargoBuildAndroid` runs `cargo ndk … build --release --lib --features
  cuprate-daemon`. The Android target only: `cargoHostLib` / `uniffiBindgen` stay
  feature-free, because the host cdylib exists only so `uniffi-bindgen --library`
  can dlopen it and the UniFFI surface does not fork on a cargo feature.
- The link needs the NDK's libc++ and compiler-rt builtins explicitly (RandomX is
  C++ and its aarch64 JIT calls `__clear_cache`; `randomx-rs` links the NDK's stub
  `libstdc++.a`). `cargo ndk --link-builtins` covers the builtins only, so the
  whole set is spelled out as per-ABI `CARGO_TARGET_<TRIPLE>_RUSTFLAGS` — a global
  `RUSTFLAGS` would break the host build scripts. The linker is the NDK clang
  driver at the app's API level, named explicitly, because the dev machines pin
  the API 21 wrapper for `aarch64-linux-android` and API 21 fails this link.
- `ANDROID_NDK` is exported alongside `ANDROID_NDK_HOME`/`NDK_HOME`: without it
  `cmake-rs` aborts and `randomx-rs`'s build script panics.
- The task logs the feature it builds with, so CI carries the request, not just
  the task name.

Wallet screen
- Third chain source, **On-device node (Cuprate)**, beside the daemon field and
  Receive-only. Stored as `ChainChoice.InProcessCuprate` with an empty
  `monerod_datadir`, which the SDK resolves to `$ONIONWIRE_HOME/chain`. Existing
  Save daemon / Receive-only / Start / Stop behaviour is unchanged.
- The status line grows `· node <word>` from `WalletChildStatus.node_state` for
  this source only, fail-closed on an unrecognised word. No sync height: the SDK
  exposes none, so the screen does not show a number it cannot get.
- Storage honesty: free space on the chain store's filesystem, and Start is
  refused below a 3 GiB floor or when that filesystem cannot be read. The floor is
  a floor, not a sync estimate — nothing here exposes one.
- The pre-production warning (quoted user book, testnet only, Cuprate issue #278)
  is a sentence above Start, assertable in a test. Opt-in, never a default.
- The daemon field's hint no longer suggests a loopback daemon on the phone.

CI
- `android-ci.yml` extracts `lib/<abi>/libonionwire_sdk.so` from the built APK and
  fails the job unless it contains `target_max_memory`, a rodata literal compiled
  only under `cuprate-daemon`. v0.7.0's shipped `.so` has zero of them, so this
  separates "in the artifact" from "requested".

Docs
- `android/CUPRATE_DAEMON.md`: the build wiring, the link line, the CI gate, and
  an explicit "not verified on a device" section. `MONERO_BINARIES.md` points at
  it for the chain source that is not a binary.
android: install cmake in the Android build containers
Some checks failed
android-ci / android (pull_request) Failing after 4m38s
ci / fuzz (pull_request) Successful in 4m34s
ci / sdk (pull_request) Failing after 10m21s
ci / test (pull_request) Failing after 10m25s
56c867b85c
RandomX is the C++ half of the in-process chain daemon and `randomx-rs`'s build
script drives it through `cmake-rs`. Neither `android-ci.yml` nor
`android-release.yml` installed `cmake` in its `debian:bookworm` container, so the
first CI run of this branch compiled 410 crates in 11m37s and then died with

    error: failed to run custom build command for `randomx-rs …`
    failed to execute command: No such file or directory (os error 2)
    is `cmake` not installed?

surfacing as Gradle's "Process 'command 'cargo'' finished with non-zero exit value
101" — which reads like a Rust error and is not one. Both workflows install it now.

`android-ci.yml` also reports the cargo target volume after the build, next to the
wall clock: the disk cost of the feature on the runner is part of the measurement
this change owes.
android: pin the Android Rust toolchain to 1.98 (cuprated needs >= 1.93)
Some checks failed
android-ci / android (pull_request) Failing after 47m45s
ci / test (pull_request) Successful in 5m11s
ci / sdk (pull_request) Successful in 1m6s
ci / fuzz (pull_request) Successful in 4m44s
86a1de814c
The Android jobs pinned `RUST_TOOLCHAIN: "1.91"` — the workspace MSRV — and the
cuprated graph does not build on it. `tapes`, a Cuprate dependency this repo cannot
patch, calls `VecDeque::pop_front_if`, stable only from 1.93:

    error[E0658]: use of unstable library feature `vec_deque_pop_if`
       --> /cargo/git/checkouts/tapes-.../src/tapes/rolling_tape.rs:396:34

1.98 is the stable release the graph is built and tested with on the dev machine
(rustc 1.98.1) and the one the cross-compile spike used. `ci.yml`, `release.yml` and
the `rust-version = "1.91"` MSRV are untouched: the feature-off workspace builds on
1.91, and moving the MSRV is a separate decision, flagged in the PR.

Both workflows, and `android/CUPRATE_DAEMON.md` records it as a pitfall.
android-ci: fix the cuprate marker gate failing its own green build
Some checks failed
android-ci / android (pull_request) Has been cancelled
ci / test (pull_request) Successful in 5m6s
ci / sdk (pull_request) Successful in 1m6s
ci / fuzz (pull_request) Successful in 4m44s
c23f38cb30
Run 406 built the APK successfully (BUILD SUCCESSFUL in 44m 7s) and the gate then
reported "the cuprate-daemon feature is NOT in this APK" while the line above it
printed `target_max_memory` **5** times. The bug is the classic one:

    strings -a x.so | grep -q pattern     # under `set -o pipefail`

`grep -q` exits at the first match and closes the pipe; `strings` takes SIGPIPE
(141) and pipefail makes the pipeline status non-zero, so `if ! ...` ran. The count
is captured into a variable now (grep -c reads the whole stream, no SIGPIPE) and the
gate fails on `< 1`, which is what it always meant.
sirius force-pushed onionwire/t_f05be394-android-build-the-sdk-with-cuprate-daemo from c23f38cb30
Some checks failed
android-ci / android (pull_request) Has been cancelled
ci / test (pull_request) Successful in 5m6s
ci / sdk (pull_request) Successful in 1m6s
ci / fuzz (pull_request) Successful in 4m44s
to 9afa22a0bf
Some checks failed
android-ci / android (pull_request) Has been cancelled
ci / test (pull_request) Successful in 5m7s
ci / sdk (pull_request) Successful in 1m4s
ci / fuzz (pull_request) Successful in 4m55s
2026-09-18 21:14:29 +00:00
Compare
android: record what the cuprated build costs CI (baseline vs feature on)
All checks were successful
android-ci / android (pull_request) Successful in 11m12s
3860c3d56d
sirius merged commit 8626da225b into main 2026-09-18 21:42:55 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!113
No description provided.