Skip to content

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#

Building#

  1. Build the library:

    cargo build --release
    
    In target/release, you should find the libmobile.dylib, libmobile.so, or libmobile.dll file, depending on the operating system you are using.

  2. .so (Shared Object) – This is the shared library format used in Linux and other Unix-based operating systems.

  3. .dylib (Dynamic Library) – This is the shared library format for macOS.
  4. .dll (Dynamic Link Library) - The shared library format used in Windows.

  5. Set up cargo-ndk for cross-compiling:

    cargo install cargo-ndk
    

  6. Add targets for Android:

    rustup target add \
            aarch64-linux-android \
            armv7-linux-androideabi \
            i686-linux-android \
            x86_64-linux-android
    

  7. 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
    

  8. Generate the bindings for Kotlin by running the command below. Replace {build_file} with libmobile.dylib, libmobile.so, or libmobile.dll, depending on which file is generated in target/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
    

  9. 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.


Last update: 2025-03-24
Created: 2021-04-16