feat(android): add cktap-android Kotlin/Android bindings via UniFFI#69
feat(android): add cktap-android Kotlin/Android bindings via UniFFI#69reez merged 5 commits intobitcoindevkit:masterfrom
Conversation
Sets up a cktap-android Gradle project that mirrors cktap-swift and follows the bdk-android structure. Cross-compiles libcktap_ffi.so for arm64-v8a, x86_64 and armeabi-v7a via the Android NDK and generates Kotlin bindings under the com.coinkite.cktap package. - Add uniffi.toml, uniffi-android.toml and .cargo/config.toml in cktap-ffi/ for Kotlin package name, Android cleaner and 16KB page size alignment - Add Android targets to rust-toolchain.toml - Add cktap-android Gradle project (AGP 8.13.2, Kotlin 2.3.10, compileSdk 34, minSdk 24, JVM 17, JNA 5.14.0) - Add release (3-arch) and dev (arm64-only) build scripts plus a justfile with build/clean/test recipes
reez
left a comment
There was a problem hiding this comment.
Excited this is in progress!
The Android binding direction looks good, but I wasn't finding the current release flow not reproducible. From a clean checkout, publishToMavenLocal -P localBuild succeeds while publishing an empty AAR, which means publish is packaging whatever happens to be under lib/src/main/kotlin and lib/src/main/jniLibs instead of building the artifact. Also im seeing the advertised full release recipe (just clean && just build macos-aarch64) currently fails at the UniFFI generate step with No UniFFI metadata found for the release-smaller Android .so, so the documented release path must be broken?
Not sure if you've run into these or its just me and I might have done something wrong.
Im assuming you're using these on the SATSBUDDY-android app so that will be nice in checking off "does this work with a real app" part 👍
- Drop `strip = true` from the `release-smaller` profile: uniffi-bindgen `--library` mode reads UNIFFI_META_* symbols from the .so, and stripping at compile time removed them, breaking the generate step with "No UniFFI metadata found". - Strip the jniLibs copies explicitly with `llvm-strip` after bindings are generated so the shipped AAR stays small. - Add a `verifyFfiArtifacts` Gradle task wired before `preBuild` that fails fast when `lib/src/main/kotlin/**/*.kt` or `lib/src/main/jniLibs/**/libcktap_ffi.so` are missing, instead of silently publishing an empty AAR.
Hi man, I just pushed some fix. Could you try again?
|
Retested. The first two issues look fixed. I still can't tell why/where the library needs android.permission.INTERNET, since I don’t see Android side networking code in the checked sources. I might be missing it or the code path that uses it? |
The library has no networking code path: no HTTP/TCP clients in deps, and the only `connect` calls in the Rust sources are `UnixStream` (emulator feature, not built for Android) and PC/SC (smartcard, not built for Android). The permission was inherited from the bdk-android template, where it is needed for Electrum/Esplora — here it just pollutes the merged manifest of every consuming app.
You all right, fixed and tested |
Description
Adds the new
cktap-androidmodule, which packages the rust-cktap library as a Kotlin/Android.aarconsumable from any Android project. The Kotlin API surface is auto-generated from thecktap-fficrate via uniffi-rs, and the AAR bundles the nativelibcktap_ffi.soforarm64-v8a,armeabi-v7a, andx86_64.What's included:
cktap-android/— Gradle Android library project (Kotlin 2.x, JDK 17, Android SDK 34, NDK 27.2.x)lib/build.gradle.kts—com.vanniktech.maven.publishsetup with Dokka, sources JAR, and alocalBuildproperty that skips GPG signing for local developmentscripts/dev/build-dev-macos-aarch64.sh— single-ABI dev build (arm64-v8a) for fast iterationscripts/release/build-release-macos-aarch64.sh— release build across all supported ABIsjustfilewith recipes:build,build-dev,clean,publish-local,publish-central,docs,testREADME.md— architecture overview (app → cktap-android → cktap-ffi → rust-cktap), usage, local Maven publish flow, and known issuescktap-ffi/.cargo/config.toml— Android target linker configurationcktap-ffi/uniffi-android.toml/uniffi.toml— UniFFI generator configuration for Androidrust-toolchain.toml— pins the toolchain for reproducible native buildsNotes to the reviewers
cktap-ffi— nothing is checked in underlib/src/main/kotlin/com/coinkite/cktap/. Thecleanjust recipe removes the generated files along withbuild/andjniLibs/.just publish-localruns./gradlew publishToMavenLocal -P localBuild. The-P localBuildflag makes signing conditional inlib/build.gradle.kts, so contributors can build the AAR without GPG keys or Sonatype credentials. Maven Central publishing (just publish-central) still requires the usual signing/credential setup.cktap-androiddepends on JNA at runtime (net.java.dev.jna:jna:5.14.0@aar). Consumers whose JVM doesn't exposecom.sun.jna.Pointermust add JNA explicitly — documented under "Known issues" in the README.org.bitcoindevkit:cktap-android:0.1.0-SNAPSHOTpending the first release tag.Changelog notice
Added
cktap-androidmodule: Kotlin/Android language bindings for rust-cktap, generated via UniFFI and packaged as an.aarwith prebuilt native libraries forarm64-v8a,armeabi-v7a, andx86_64.Checklists
All Submissions:
cargo fmtandcargo clippybefore committingNew Features: