-
Notifications
You must be signed in to change notification settings - Fork 3
Fix Android binding generation and local build setup #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ edition = "2021" | |
| authors = ["World Contributors"] | ||
| readme = "./README.md" | ||
| homepage = "https://docs.world.org" # TODO: Update to specific WalletKit page | ||
| rust-version = "1.86" # MSRV | ||
| rust-version = "1.91" # MSRV | ||
| repository = "https://github.com/worldcoin/walletkit" | ||
| exclude = ["tests/", "uniffi-bindgen/"] | ||
| keywords = ["ZKP", "WorldID", "World", "Identity", "Semaphore"] | ||
|
|
@@ -26,6 +26,5 @@ world-id-core = { version = "0.3", default-features = false, features = ["authen | |
| [profile.release] | ||
| opt-level = 'z' # Optimize for size. | ||
| lto = true # Enable Link Time Optimization. | ||
| strip = true # Automatically strip symbols from the binary. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the culprit of preventing bindings to get exposed and available from |
||
| panic = "abort" | ||
| debug = false | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,14 +28,52 @@ WalletKit's bindings for Kotlin are distributed through GitHub packages. | |||||||
| ```kotlin | ||||||||
| dependencies { | ||||||||
| /// ... | ||||||||
| implementation "org.world:walletkit:VERSION" | ||||||||
| implementation "org.world:walletkit-android:VERSION" | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. walletkit/kotlin/lib/build.gradle.kts Line 52 in 9916b32
walletkit?
|
||||||||
| } | ||||||||
| ``` | ||||||||
|
|
||||||||
| Replace `VERSION` with the desired WalletKit version. | ||||||||
|
|
||||||||
| 2. Sync Gradle. | ||||||||
|
|
||||||||
| ## Local development (Android/Kotlin) | ||||||||
|
|
||||||||
| ### Prerequisites | ||||||||
|
|
||||||||
| 1. **Docker Desktop**: Required for cross-compilation | ||||||||
| - The build uses [`cross`](https://github.com/cross-rs/cross) which runs builds in Docker containers with all necessary toolchains | ||||||||
| - Install via Homebrew: | ||||||||
| ```bash | ||||||||
| brew install --cask docker | ||||||||
| ``` | ||||||||
| - Launch Docker Desktop and ensure it's running before building | ||||||||
|
|
||||||||
| 2. **Android SDK + NDK**: Required for Gradle Android tasks | ||||||||
| - Install via Android Studio > Settings > Android SDK (ensure the NDK is installed) | ||||||||
| - Set `sdk.dir` (and `ndk.dir` if needed) in `kotlin/local.properties` | ||||||||
|
|
||||||||
| 3. **Protocol Buffers compiler**: | ||||||||
| ```bash | ||||||||
| brew install protobuf | ||||||||
| ``` | ||||||||
|
|
||||||||
| ### Building and publishing | ||||||||
|
|
||||||||
| To test local changes before publishing a release, use the build script to compile the Rust library, generate UniFFI bindings, and publish a SNAPSHOT to Maven Local: | ||||||||
|
|
||||||||
| ```bash | ||||||||
| ./build_android_local.sh 0.3.1-SNAPSHOT | ||||||||
| ``` | ||||||||
|
|
||||||||
| > **Note**: The script sets `RUSTUP_HOME` and `CARGO_HOME` to `/tmp` by default to avoid Docker permission issues when using `cross`. You can override them by exporting your own values. | ||||||||
|
|
||||||||
| This will: | ||||||||
| 1. Build the Rust library for all Android architectures (arm64-v8a, armeabi-v7a, x86_64, x86) | ||||||||
| 2. Generate Kotlin UniFFI bindings | ||||||||
| 3. Publish to `~/.m2/repository/org/world/walletkit-android/` | ||||||||
|
|
||||||||
| In your consuming project, ensure `mavenLocal()` is included in your repositories and update your dependency version to the SNAPSHOT version (e.g., `0.3.1-SNAPSHOT`). | ||||||||
|
|
||||||||
| ## Overview | ||||||||
|
|
||||||||
| WalletKit is broken down into separate crates, offering the following functionality. | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| echo "Building WalletKit Android SDK for local development..." | ||
|
|
||
| # Set rustup and cargo home to /tmp to prevent Docker permission issues | ||
| export RUSTUP_HOME="${RUSTUP_HOME:-/tmp/.rustup}" | ||
| export CARGO_HOME="${CARGO_HOME:-/tmp/.cargo}" | ||
|
|
||
| # Version is required | ||
| if [ -z "$1" ]; then | ||
| echo "Error: Version parameter is required" | ||
| echo "Usage: ./build_android_local.sh <version>" | ||
| echo "Example: ./build_android_local.sh 0.2.1-SNAPSHOT" | ||
| exit 1 | ||
| fi | ||
|
|
||
| VERSION="$1" | ||
| echo "Using version: $VERSION" | ||
|
|
||
| # Build using kotlin/build.sh | ||
| echo "Building WalletKit SDK..." | ||
| cd kotlin | ||
| ./build.sh | ||
|
|
||
| # Publish to Maven Local | ||
| echo "Publishing to Maven Local..." | ||
| ./gradlew :lib:publishToMavenLocal -PversionName="$VERSION" | ||
|
|
||
| echo "" | ||
| echo "✅ Successfully published $VERSION to Maven Local!" | ||
| echo "Published to: ~/.m2/repository/org/world/walletkit-android/$VERSION/" | ||
| echo "" | ||
| echo "To use in your project:" | ||
| echo " implementation 'org.world:walletkit-android:$VERSION'" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,15 @@ | ||
| # Ignore Gradle project-specific cache directory | ||
| *.iml | ||
| .gradle | ||
|
|
||
| # Ignore Gradle build output directory | ||
| build | ||
| /local.properties | ||
| /.idea/caches | ||
| /.idea/libraries | ||
| /.idea/modules.xml | ||
| /.idea/workspace.xml | ||
| /.idea/navEditor.xml | ||
| /.idea/assetWizardSettings.xml | ||
| .DS_Store | ||
| /build | ||
| /captures | ||
| .externalNativeBuild | ||
| .cxx | ||
| local.properties |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
| plugins { | ||
| id("com.android.application") version "8.3.0" apply false | ||
| id("com.android.library") version "8.3.0" apply false | ||
| id("org.jetbrains.kotlin.android") version "1.9.22" apply false | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| echo "Building WalletKit Android SDK..." | ||
|
|
||
| # Create jniLibs directories | ||
| mkdir -p ./lib/src/main/jniLibs/{arm64-v8a,armeabi-v7a,x86_64,x86} | ||
|
|
||
| # Build for all Android architectures | ||
| echo "Building for aarch64-linux-android..." | ||
| cross build -p walletkit --release --target=aarch64-linux-android | ||
|
|
||
| echo "Building for armv7-linux-androideabi..." | ||
| cross build -p walletkit --release --target=armv7-linux-androideabi | ||
|
|
||
| echo "Building for x86_64-linux-android..." | ||
| cross build -p walletkit --release --target=x86_64-linux-android | ||
|
|
||
| echo "Building for i686-linux-android..." | ||
| cross build -p walletkit --release --target=i686-linux-android | ||
|
|
||
| # Move .so files to jniLibs | ||
| echo "Moving native libraries..." | ||
| mv ../target/aarch64-linux-android/release/libwalletkit.so ./lib/src/main/jniLibs/arm64-v8a/libwalletkit.so | ||
| mv ../target/armv7-linux-androideabi/release/libwalletkit.so ./lib/src/main/jniLibs/armeabi-v7a/libwalletkit.so | ||
| mv ../target/x86_64-linux-android/release/libwalletkit.so ./lib/src/main/jniLibs/x86_64/libwalletkit.so | ||
| mv ../target/i686-linux-android/release/libwalletkit.so ./lib/src/main/jniLibs/x86/libwalletkit.so | ||
|
|
||
| # Generate Kotlin bindings | ||
| echo "Generating Kotlin bindings..." | ||
| cargo run -p uniffi-bindgen generate \ | ||
| ./lib/src/main/jniLibs/arm64-v8a/libwalletkit.so \ | ||
| --library \ | ||
| --language kotlin \ | ||
| --no-format \ | ||
| --out-dir lib/src/main/java | ||
|
|
||
| echo "✅ Build complete!" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /build | ||
| /src/main/java/uniffi/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| * | ||
| !.gitignore |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| [toolchain] | ||
| channel = "1.91.0" | ||
| profile = "default" | ||
| components = ["rustfmt", "clippy", "rust-analyzer"] | ||
| targets = [ | ||
| "aarch64-apple-ios-sim", | ||
| "aarch64-apple-ios", | ||
| "x86_64-apple-ios", | ||
| "x86_64-unknown-linux-gnu", | ||
| "aarch64-linux-android", | ||
| "armv7-linux-androideabi", | ||
| "x86_64-linux-android", | ||
| "i686-linux-android", | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bumped the
rust-versionas I was running intoFormat, Clippy & BuildandTestsissues https://github.com/worldcoin/walletkit/actions/runs/21117220277