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

Micro-native packages

Embed a React or Octane feature with its own bundle, baked first screen, typed modules and update contract.

A team can ship a React or Octane feature inside an existing native app. The feature package contains its Hermes bytecode, the baked first render (app.baked), the manifest, assets and its native modules. The host links one copy of the BakeNative runtime, chooses when to show the screen and supplies the host capabilities declared by the feature. Each root has its own JS state and module registry.

The step-by-step guide (declaring, building, adding to a host, the checks) is App packages. This page explains the model and how it fits with the rest of BakeNative.

Two kinds of parts

PartiOSAndroidHow many
Runtime: Rust core, Hermes, the platform hostBakeNative.xcframeworkthe runtime AAR (dev.bakenative:bakenative)One per host app, shared by every app
App package: one app's code, bundle and modules<App>.xcframework (static)<app>.aarOne per app

The host links the Rust engine, Hermes and platform host code once. Each feature chooses its renderer and can adopt its own baked screen before applying live updates.

bake package builds the iOS package today. It packs ios only; asked for another target, it fails with bake package packs ios only. On Android the package AAR comes from the app's own Gradle library, and the bake checks below already read it. What bake package --target android will write is on App packages: Android.

The host only adds parts

import Norrow
import Showcase

navigationController?.pushViewController(Norrow.makeViewController(), animated: true)
  • Module visibility. A screen sees the runtime modules, the modules in its own package and the host capabilities its package declares. A module registered by another feature is private to that feature.
  • Separate storage. Storage is scoped by the package id, so two packages never share keys.
  • Capabilities are declared. A host feature a package needs, such as a login token, is a native module the host passes in (capabilities:). The package must list it in requires, and bake build fails when the JS calls a module that is neither the package's, the runtime's nor a declared capability.

Details: App packages: isolation.

Compatibility: JS against native

JS and native ship separately. The JS bundle can be replaced over the air; the native code changes only with an app release. So the JS and the native code of the same app are checked against each other every time one of them moves.

The rule is requires ⊆ provides:

  • bake build writes what the bundle requires into its manifest.json: the signature of every native function it calls, the first-party modules it uses (requires.modules), the renderer ops, events and CSS properties it uses, and the package id.
  • The package lists what it provides in BakeNativePackage.json: the signatures of its modules, the first-party modules compiled into it (provides.modules), its native build number, and the runtime it was built with. On Android, the app's BakeNativePackage also provides the first-party modules and native views the app links.
  • A bundle runs only when every requirement is provided with the same shape. A change breaks a bundle only when the bundle used what changed. Adding a function or a module breaks nothing.

The member signatures are the package's native fingerprint: a hash per native function, of its module, name, kind, parameter types and return type. Parameter names are not part of it.

It is checked in three places:

  1. bake build fails, with the file and line, when the JS calls a native function the package does not have.

  2. bake release check runs in CI before an OTA release:

    bake release check dist/ios --against Norrow.xcframework

    It exits with 1 and prints every reason when the device would refuse the bundle. --against also takes an Android package AAR or the app's APK.

  3. On the device, the core refuses a bundle that does not fit, and the package keeps running its embedded bundle.

The full rules, the escape hatches (nativeBuild, runtime) and every refusal message: App packages: OTA compatibility. How a host applies a downloaded bundle: Shipping updates.

With the module registry and feature tiers

A package is the same app, packed. The feature tiers still decide where each native feature comes from, and every tier ends up inside the package:

TierIn a package
Built-in (fetch, <img>, <video>)fetch and <img> are in the shared runtime; <video>'s player is linked into the app or package whose bundles render it (provides.views)
First-party and third-party modulesCompiled into the package. Only the ones the bundle uses: provides.modules
App modulesCompiled into the package from the package's modules directory

First-party and third-party modules the app takes from a source registry become the app's own source files, so they are compiled into that app's package like the app's own modules, and the package's provides lists them. Third-party native libraries that such code links (an SDK, an .so) must be declared, shared or isolated: App packages: third-party libraries.

The module registry of a package's screen has the same layers as in any host: the runtime's built-in modules, then the package's modules. A capability the host passes is added to that screen's registry before its bundle runs, like any other module.

Several apps in one host

A brownfield host that shows more than one BakeNative feature adds one package per app next to the one runtime:

dependencies:
  - framework: Frameworks/BakeNative.xcframework
    embed: true
  - framework: Frameworks/Norrow.xcframework
    embed: true
  - framework: Frameworks/Showcase.xcframework
    embed: true

Each team releases its own package and its own OTA bundles, gated by bake release check. The host team owns the runtime: when it ships another runtime, every package's bundles are compared against it on the device, and a bundle that no longer fits falls back to its package's embedded bundle.

Before adding packages to one host, check that they fit together (shared third-party versions overlap, package identities do not collide):

bake package host-check norrow.aar showcase.aar dist/ios-package/

examples/package-host-ios in the repository is a complete host with two packages. For a single screen in an existing app, see Brownfield.

One app as a Swift package

To ship a single app as prebuilt binaries that an iOS or macOS app adds as a Swift package, without the multi-app setup, see Ship as a Swift package.

On this page