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 --release
target/release
, you should find thelibmobile.dylib
,libmobile.so
, orlibmobile.dll
file, depending on the operating system you are using. -
.so (Shared Object) – This is the shared library format used in Linux and other Unix-based operating systems.
- .dylib (Dynamic Library) – This is the shared library format for macOS.
-
.dll (Dynamic Link Library) - The shared library format used in Windows.
-
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}
withlibmobile.dylib
,libmobile.so
, orlibmobile.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.
Created: 2021-04-16