Using UniFFI binding Android App#
Cedarling UniFFI binding exposes its init
, authz
and log
interfaces to different languages and on all the different platforms, including Kotlin for Android. This section covers how to build and use Cedarling UniFFI binding in an Android app.
Prerequisites#
- Rust: Install it from the official Rust website.
- Android Studio: Download from the official site.
Building#
-
Build the library:
Incargo build -r -p cedarling_uniffi
target/release
, you should find thelibcedarling_uniffi.dylib
(if Mac OS),libcedarling_uniffi.so
(if Linux OS), orlibcedarling_uniffi.dll
(if Windows OS) file, depending on the operating system you are using. -
Set up cargo-ndk for cross-compiling:
cargo install cargo-ndk
-
Add targets for Android:
rustup target add \ aarch64-linux-android \ armv7-linux-androideabi \ i686-linux-android \ x86_64-linux-android
-
Compile the dynamic libraries in ./app/src/main/jniLibs (next to java and res directories) in the sample
androidApp
project.cargo ndk -o ./bindings/cedarling_uniffi/androidApp/app/src/main/jniLibs \ --manifest-path ./Cargo.toml \ -t armeabi-v7a \ -t arm64-v8a \ -t x86 \ -t x86_64 \ build \ -p cedarling_uniffi --release
-
Generate the bindings for Kotlin by running the command below. Replace
{build_file}
withlibcedarling_uniffi.dylib
,libcedarling_uniffi.so
, orlibcedarling_uniffi.dll
, depending on which file is generated intarget/release
.cargo run --bin uniffi-bindgen generate --library ./target/release/{build_file} --language kotlin --out-dir ./bindings/cedarling_uniffi/androidApp/app/src/main/java/com/example/androidapp/cedarling/uniffi
-
We have included a sample android app using Cedarling UniFFI binding for making authorisation decisions. Open the
androidApp
project on Android Studio and run the project on simulator.