Skip to main content

Module android

Module android 

Source
Available on crate feature full only.
Expand description

Android build automation.

This module provides AndroidBuilder which handles the complete pipeline for building Rust libraries for Android and packaging them into an APK using Gradle.

§Build Pipeline

The builder performs these steps:

  1. Project scaffolding - Auto-generates Android project if missing
  2. Rust compilation - Builds native .so libraries for Android ABIs using cargo-ndk
  3. Binding generation - Generates UniFFI Kotlin bindings
  4. Library packaging - Copies .so files to jniLibs/ directories
  5. APK building - Runs Gradle to build the app APK
  6. Test APK building - Builds the androidTest APK for BrowserStack Espresso

§Requirements

  • Android NDK (set ANDROID_NDK_HOME environment variable)
  • cargo-ndk (cargo install cargo-ndk)
  • Rust targets: aarch64-linux-android, armv7-linux-androideabi, x86_64-linux-android
  • Java JDK (for Gradle)

§Example

use mobench_sdk::builders::AndroidBuilder;
use mobench_sdk::{BuildConfig, BuildProfile, Target};

let builder = AndroidBuilder::new(".", "my-bench-crate")
    .verbose(true)
    .dry_run(false);  // Set to true to preview without building

let config = BuildConfig {
    target: Target::Android,
    profile: BuildProfile::Release,
    incremental: true,
};

let result = builder.build(&config)?;
println!("APK at: {:?}", result.app_path);
println!("Test APK at: {:?}", result.test_suite_path);

§Dry-Run Mode

Use dry_run(true) to preview the build plan without making changes:

let builder = AndroidBuilder::new(".", "my-bench")
    .dry_run(true);

// This will print the build plan but not execute anything
builder.build(&config)?;

Structs§

AndroidBuilder
Android builder that handles the complete build pipeline.