BakeNative is under active development. APIs may change.
Skip to Content
BakeNative

Ship as an Android AAR

Build the BakeNative runtime for Android into a Maven AAR with one native library per ABI, and add it to an app that has no BakeNative checkout.

The runtime AAR is the Android host as a Maven package: BakeNativeView, the Kotlin host, and one native library, libbakenative.so, per ABI. An app adds one dependency. It needs no NDK, CMake, Rust or Hermes build of its own.

1. Build the AAR

pnpm hermes -- --android --static          # Hermes as static archives (once per Hermes pin)
pnpm android:aar                           # libbakenative.so per ABI + the AARs in build/maven
build/android-runtime/
  arm64-v8a/libbakenative.so      the runtime: Rust core + Hermes + C++ runtime, one shared object
  x86_64/libbakenative.so
  sizes.json                   bytes and gzip bytes per ABI
build/maven/dev/bakenative/
  bakenative/<version>/           BakeNativeView, the Kotlin host and jni/<abi>/libbakenative.so
  bakenative-controls/<version>/  form controls, sheets, text inputs (Compose / EditText)
  bakenative-modules/<version>/   the native module runtime (spec contracts, registry)

--abis arm64-v8a builds one ABI, --maven <dir> publishes to another repository, and --version <v> overrides the version (default: the @bake-native/core package version).

2. Add it to the app

// settings.gradle.kts
dependencyResolutionManagement {
    repositories {
        maven { url = uri("/path/to/bakenative/build/maven") }
        google()
        mavenCentral()
    }
}

// app/build.gradle.kts
dependencies {
    implementation("dev.bakenative:bakenative:0.0.1")
}

Copy the bundle (bake build --target android --bake: app.hbc, app.baked, app.css, manifest.json) into the APK's assets, for example as bakenative/app/, and show it:

val view = BakeNativeView(this)
setContentView(view)
view.load(BakeNativeBundle.Asset("bakenative/app"))

Add generated modules and views

Add .bake/native/android/src/main/kotlin from bake build to the app's Kotlin source set. The AAR supports app-declared Kotlin views that use props and events. Use the generated BakeNativeBundleModules.root(...) and BakeNativeAppViews.views() to register them before you call load.

The repository fixture in tests/android-runtime-aar uses a generated module and a native button. Build it after publishing the local AAR.

pnpm --filter @bake-native/android-runtime-aar-fixture build
native/android/gradlew -p tests/android-runtime-aar :app:assembleDebug

Run the fixture with the Android E2E runner. It checks the module response, the button event, and the prop update after a tap.

E2E_ANDROID_SERIAL=emulator-5630 pnpm --filter @bake-native/e2e-tests exec e2e run --config e2e.android-aar.config.ts

How the library is built

tools/build-android-aar/build.mjs links libbakenative.so with the NDK's clang from three static parts:

PartBuilt by
Rust corecargo ndk … rustc --crate-type staticlib -p bake-host-android --features runtime-aarthe bake_* C ABI over JNI, text, paint, modules, JNI_OnLoad
Hermes + bridgetools/build-hermes/android.sh --statichermesvm_a, jsi, boost_context and the bridge in one archive (android/<abi>/static/libbakehermes.a), with hidden visibility and one section per function
C++ runtimethe NDK (ANDROID_STL=c++_static, -static-libstdc++)
  • One exported symbol. A version script exports JNI_OnLoad and makes everything else local, and --gc-sections drops the code it does not reach. JNI_OnLoad registers every JNI function with RegisterNatives from a generated table (bake-host-android/src/natives.rs, written by tools/build-android-aar/natives.mjs from the Kotlin external fun declarations and the Rust Java_* functions). A method whose descriptor does not match its Kotlin declaration fails the load, not a later call.
  • System libraries only. The library needs liblog, libandroid, libc, libm and libdl. No Hermes, JSI, C++ runtime or Rust symbol is visible to the app, so it can live next to another runtime's Hermes or libc++_shared.so.
  • Checked every build. llvm-readelf --dyn-syms must list JNI_OnLoad as the only defined symbol, and NEEDED must list only those system libraries. pnpm check runs the same check on the libraries in build/android-runtime (node tools/build-android-aar/elf.mjs --built), and checks that the registration table matches the sources.
  • 16 KB pages. The library is linked with -z max-page-size=16384, so it loads on 4 KB and 16 KB page devices.

The 0.1.0 build recorded these sizes. build/android-runtime/sizes.json reports the sizes for each build.

ABIlibbakenative.sogzip
arm64-v8a8.24 MB3.97 MB
x86_649.17 MB4.18 MB

The development host (native/android/bakenative/build-rust.sh) is unchanged: it packages libbakenative.so, libbakehermes.so, libhermesvm.so and libc++_shared.so, and loads Hermes on the JS thread.

Next to React Native

A React Native 0.79 app (Hermes, new architecture) takes the AAR as a plain dependency on its own AGP 8.8, compileSdk 35 and Kotlin 2.0.21, with the AAR metadata check on and no pickFirst or packaging rules; only minSdkVersion goes from 24 to 29. Its APK then holds React Native's libhermes.so, libjsi.so and libc++_shared.so next to libbakenative.so, and both runtimes run in one process: the React Native screen, then an BakeNativeView in another Activity, each running its own Hermes.

minSdk 29

The host app needs minSdk 29 (Android 10) or higher; React Native's template sets 24, so raise it:

// android/build.gradle
buildscript {
    ext {
        minSdkVersion = 29   // the template's 24 is below the AAR's minSdk
    }
}

Without it the build stops at the manifest merge with this error. The fix is that one line. tools:overrideLibrary only moves the failure to devices below Android 10, at run time:

Manifest merger failed : uses-sdk:minSdkVersion 24 cannot be smaller than version 29 declared in library [dev.bakenative:bakenative:0.0.1] .../AndroidManifest.xml as the library might be using APIs not available in 24
	Suggestion: use a compatible library with a minSdk of at most 24,
		or increase this project's minSdk version to at least 29,
		or use tools:overrideLibrary="dev.bakenative" to force usage (may lead to runtime failures)

Limits

  • Kotlin. The AAR's own classes are compiled for Kotlin 2.0 consumers (language and API version 2.0, kotlin-stdlib / kotlin-reflect 2.0.21). Compose 1.11 brings kotlin-stdlib 2.1.20, which Kotlin 2.0.21 reads.
  • Floor: compileSdk 35, AGP 8.6, minSdk 29. bakenative-controls uses Compose 1.11 (BOM 2026.06.01, the last before Compose 1.12 requires compileSdk 37 and AGP 9.1), and the AARs declare compileSdk 35 to the AAR metadata check. React Native 0.79 (AGP 8.8, compileSdk 35, Kotlin 2.0.21) builds with the check on; its template's minSdkVersion 24 must be raised to 29, the AAR's own minSdk.
  • C++ native-view commands. Use the development host from a source checkout for native views whose C++ commands use JSI and kolibri, such as the video player.
  • Local Maven only. The AAR is published to a local repository. Hosting it on a Maven server is not set up.

On this page