onionwire/android/app/build.gradle.kts
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

159 lines
6.5 KiB
Kotlin

import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
}
fun envOrNull(name: String): String? =
System.getenv(name)?.takeIf { it.isNotBlank() }
android {
namespace = "com.siriusdevops.onionwire"
compileSdk = 36
// Same ABI selection as :sdk. JNA ships libjnidispatch.so for several ABIs;
// without this filter the APK carries native code for ABIs we never built
// our Rust lib for.
val onionwireAbis: List<String> = (findProperty("onionwire.abis") as String?)
?.split(',')?.map(String::trim)?.filter(String::isNotEmpty)
?: listOf("arm64-v8a")
defaultConfig {
applicationId = "com.siriusdevops.onionwire"
minSdk = 26
targetSdk = 36
// CI/local release scripts override both via -P. Committed values are
// the offline default and match the first automated tag (v0.1.0 → 100).
versionCode = (findProperty("onionwire.versionCode") as String?)?.toIntOrNull() ?: 100
versionName = (findProperty("onionwire.versionName") as String?) ?: "0.1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters += onionwireAbis
}
}
signingConfigs {
create("release") {
val ksPath = envOrNull("ANDROID_KEYSTORE_FILE")
if (ksPath != null) {
storeFile = file(ksPath)
storePassword = envOrNull("ANDROID_KEYSTORE_PASSWORD")
?: error("ANDROID_KEYSTORE_PASSWORD is required when ANDROID_KEYSTORE_FILE is set")
keyAlias = envOrNull("ANDROID_KEY_ALIAS")
?: error("ANDROID_KEY_ALIAS is required when ANDROID_KEYSTORE_FILE is set")
keyPassword = envOrNull("ANDROID_KEY_PASSWORD")
?: error("ANDROID_KEY_PASSWORD is required when ANDROID_KEYSTORE_FILE is set")
}
}
}
buildTypes {
debug {
// Sideload / device-test builds. Signed with the standard debug key.
applicationIdSuffix = ".debug"
versionNameSuffix = "-debug"
}
release {
// Deliberately NOT minified in this card: there is no on-device
// crash-deobfuscation story yet, and shipping R8 without testing
// the JNI/uniffi surface on a real device is how you get a
// mysterious UnsatisfiedLinkError in the field.
// Enable together with mapping-file upload; keeps already exist in
// :sdk/consumer-rules.pro.
isMinifyEnabled = false
isShrinkResources = false
// Repo-owned release keystore via ANDROID_KEYSTORE_* env (Forgejo
// secrets in CI, ~/.android/onionwire-release.env locally). CI sets
// ONIONWIRE_REQUIRE_RELEASE_KEY=true and fails closed if missing —
// the debug keystore is per-machine and would break in-place upgrades.
val requireReleaseKey =
(findProperty("onionwire.requireReleaseKey") as String?) == "true" ||
envOrNull("ONIONWIRE_REQUIRE_RELEASE_KEY") == "true"
val releaseSigning = signingConfigs.getByName("release")
val releaseStore = releaseSigning.storeFile
signingConfig = when {
releaseStore != null && releaseStore.isFile -> releaseSigning
requireReleaseKey -> error(
"Release keystore required but ANDROID_KEYSTORE_FILE is missing or not a file"
)
else -> {
logger.warn(
"No ANDROID_KEYSTORE_FILE; signing the release APK with the debug keystore. " +
"CI must not do this — in-place upgrades will break."
)
signingConfigs.getByName("debug")
}
}
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildFeatures {
compose = true
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
jniLibs {
// `android:extractNativeLibs="true"`. This is what puts
// `libmonerowalletrpc.so` on disk in `ApplicationInfo.nativeLibraryDir`
// at install time, which is the ONLY directory Android lets an app
// `exec()` from (since API 29 a file in `filesDir` is not executable
// whatever its mode bits say). With the AGP 8 default
// (`extractNativeLibs="false"`) the wallet binary would stay inside
// the APK and `start_wallet_child` would fail with ENOENT on a path
// that looks correct. See android/MONERO_BINARIES.md.
useLegacyPackaging = true
// The wallet child is an executable, not a linked library, and
// scripts/build-monero-wallet-rpc-android.sh already stripped it with
// the target's own strip. Excluding it from AGP's strip pass keeps the
// bytes in the APK identical to the committed blob, which is what
// scripts/build-android-local.sh verifies in CI.
keepDebugSymbols += "**/libmonerowalletrpc.so"
}
}
}
kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
dependencies {
implementation(project(":sdk"))
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.navigation.compose)
implementation(platform(libs.compose.bom))
implementation(libs.compose.ui)
implementation(libs.compose.ui.graphics)
implementation(libs.compose.ui.tooling.preview)
implementation(libs.compose.material3)
debugImplementation(libs.compose.ui.tooling)
testImplementation(libs.junit)
testImplementation(libs.kotlinx.coroutines.test)
// Device-only: the AndroidKeyStore provider does not exist in the unit-test
// JVM. These run under `./gradlew :app:connectedDebugAndroidTest`.
androidTestImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.androidx.test.runner)
// QR code rendering for the wallet receive-address screen.
implementation(libs.zxing)
}