App packages
Ship each BakeNative app as its own framework, with its own native modules, on one shared runtime, and check that JS and native still fit before every release.
An app package is one BakeNative app as a native part: its JS bundle, its first screen, and the native modules it uses. A host app adds the shared runtime once and any number of packages next to it. The host calls the package entry point and injects any host capabilities the package explicitly declares.
| Part | iOS | Android (planned) | How many |
|---|---|---|---|
| Runtime: Rust core, Hermes, the UIKit / Android host | BakeNative.xcframework | the runtime AAR (dev.bakenative:bakenative) | one per host app, versioned |
| Package: one app's code, bundle and modules | <App>.xcframework (static) | <app>.aar | one per app |
Every app shares one runtime, so adding an app adds only its own code and bundle, and the Rust and Hermes symbols exist once in the process.
1. Declare the package
In the app's package.json:
{
"name": "@acme/norrow",
"version": "1.0.0",
"bakenative": {
"package": {
"name": "Norrow",
"id": "dev.bakenative.example.norrow",
"modules": "native/ios",
"schema": "native-modules.json",
"requires": [],
"runtime": ">=0.0.1 <0.1.0"
}
}
}| Field | Meaning | Default |
|---|---|---|
name | Swift module and entry point (Norrow.makeViewController()) | from name |
id | Package id: the OTA bundle must name it; also the Storage scope | dev.bakenative.app.<name> |
modules | Directory of the app's own native modules' Swift implementations | none |
schema | Signatures of modules without a spec (a schema a host wrote); the specs in native/<name>/ give the rest | native-modules.json |
requires | Host capabilities the app may use | [] |
runtime | Runtimes the package runs on; when declared, its OTA bundles require it too | the series it is built with, e.g. >=0.0.1 <0.1.0 |
nativeBuild | Raise when native behavior changes behind unchanged signatures (step 5) | 0 |
2. Add a native module
bake native new NorrowShare --platform apple --target NorrowDeclare the module in native/norrow-share/NorrowShare.native.ts and implement the generated
NorrowShareSpec in the modules directory (Native modules).
bake package generates the contract into the package, and the spec gives the signatures the
package provides; bake native types writes the JS types.
import { native, hasNative } from '@bake-native/octane';
// In a handler, not during render: the snapshot bake has no native modules.
if (hasNative('NorrowShare')) await native.NorrowShare.share(product.name, product.url);Keep native calls out of render, and guard them with hasNative when the same source also runs on
hosts that do not ship the module (the web, other hosts).
3. Build the package
bake package --target ios # in the app directory; --runtime <BakeNative.xcframework> outside the monorepodist/ios-package/
Norrow.xcframework
ios-arm64/Norrow.framework and ios-arm64-simulator/
Norrow static archive: NorrowShareModule + the generated entry point
Modules/Norrow.swiftmodule/ .swiftinterface only (library evolution)
BakeNativeApp/
app.hbc app.baked app.css the bundle (baked first screen)
manifest.json the bundle manifest, with what the bundle requires
BakeNativePackage.json what the package provides (below)
assets/ the app's assets/ directory, if any
BakeNativePackage.json a copy for CIbake package builds the target with --bake, checks the native module uses (step 5), and compiles
the module sources and the entry point against the runtime. The package links the runtime; it does
not contain it.
4. Add packages to a host
Add BakeNative.xcframework and each package to the app target, all with Embed & Sign. Embedding
a static package copies its BakeNativeApp/ resources into the app's Frameworks/, and Xcode links
its code into the app binary. With XcodeGen:
dependencies:
- framework: Frameworks/BakeNative.xcframework
embed: true
- framework: Frameworks/Norrow.xcframework
embed: true
- framework: Frameworks/Showcase.xcframework
embed: trueThe host code:
import Norrow
import Showcase
navigationController?.pushViewController(Norrow.makeViewController(), animated: true)
// Prepare the first screens while the host's screen is up (no JS), so a push shows them at once.
Norrow.prewarm()
Showcase.prewarm()In SwiftUI, use NorrowView(). examples/package-host-ios is a complete host: an empty app with two
buttons (./build.sh && xcodegen generate).
The generated entry point of a package:
| API | What it does |
|---|---|
<App>.makeViewController(capabilities:hydration:) | the app's screen, with the package's modules |
<App>View(capabilities:hydration:) | the same in SwiftUI |
<App>.prewarm() | prepares the first screen without JS |
<App>.use(update:) | offers an OTA bundle directory; returns .accept or .reject(reason) |
<App>.package | the BakeNativePackage: manifest, embedded and active bundle |
Isolation
- Modules. Every screen of a package registers the package's own modules and the runtime
modules (
Platform,Storage,Haptics,Clipboard,Linking,Share). The host's modules are never visible to it. Give the package's modules names of their own: a runtime module's name is left out of the fingerprint. - Storage.
Storageis scoped by the packageid, so two packages never share keys. - Capabilities. A host feature a package needs (a login token, navigation) is a native module
the host injects:
Norrow.makeViewController(capabilities: [AuthModule()]). The package must list it inrequires. The package does not start (it shows the reason instead) when a required capability is missing, when the host passes one that is not declared, or when one has the name of a package or runtime module.bake buildfails when the JS usesnative.XandXis neither a package module, a runtime module nor a declared capability.
5. OTA compatibility: requires and provides
JS and native ship separately: the JS bundle can be updated over the air, the native code only with an app release. Whether a bundle may run in an installed package is decided item by item, not by comparing one hash of everything: the bundle lists what it requires, the runtime and the package list what they provide, and the bundle runs when every requirement is provided with the same shape.
So a change breaks an existing bundle only when the bundle used what changed:
| Change in the app release | Bundles built before it |
|---|---|
| A native function added to a module, or a new module | still run |
| Native code changed behind the same signatures | still run |
| A native function the bundle does not call removed or changed | still run |
| A runtime that adds renderer ops, events or CSS properties, or renumbers ops | still run |
| A native function the bundle calls removed, or its signature changed | refused |
| A renderer op, event or CSS property the bundle uses removed or reshaped | refused |
| Another package | refused |
Each mini-app team owns its range: it declares what its bundles need (its own modules' signatures,
optionally a runtime range and a nativeBuild) and gates its OTA releases with bake release check.
The host team owns the shared runtime: when it ships another runtime, every package's bundles are
compared against it automatically, and a bundle that no longer fits falls back to the package's
embedded bundle on the device.
What a bundle requires
bake build writes requires into the bundle's manifest.json (see the
manifest reference):
"requires": {
"format": 1,
"batch": {
"stream": "df3b82fcd9fa877c",
"seed": { "count": 52, "hash": "…" },
"ops": { "create": { "tag": 1, "shape": "ceedecf0869e4cc1" }, "…": {} }
},
"events": ["click", "input"],
"style": ["background-color", "color", "padding"],
"package": "dev.bakenative.example.norrow",
"native": { "NorrowShare.share": "d6ac2802a0846f1f" }
}batch: the renderer batch stream itsapp.hbcwrites.streamhashes what every op shares (encoding, header, interned tables), each op has its tag and a hash of its fields (shape, the tag left out), andseednames the built-in strings it knows. Generated frombatch.oschema(packages/core/batch-contract.json).events: the events its markup listens to (onClick→click), andstylethe CSS properties it declares (inapp.cssand literal inline styles). Only what the runtime of the building toolchain provides is listed; anything else is already a build error or ignored on native.packageandnative, in a packaged app: the package id and the signature of every native member the sources call. A dynamic access (native.NorrowShare[name],native.NorrowSharepassed around) requires every member of that module,native[name]every member of every package module.nativeBuildandruntime, only when the app declares them (below).
A member signature is FNV-1a 64 of <Module>.<member>:<kind>(<type>[?],...)-><returns>.
Parameter names are not part of it. Changing a parameter's type or optionality, the return type,
or the kind (sync, async, constant) changes it.
What a package provides
BakeNativePackage.json (format 2) has provides:
"provides": {
"package": "dev.bakenative.example.norrow",
"nativeBuild": 0,
"native": { "NorrowShare.available": "dcb4ce32defa1c74", "NorrowShare.share": "d6ac2802a0846f1f" },
"hermesBytecode": 96,
"modules": ["Share"],
"runtime": { "format": 1, "runtime": "0.0.1", "hostProtocol": 4, "batch": { "…": {} }, "events": ["…"], "style": ["…"] }
}views (when the bundle renders a native view, such as <video>'s player) maps each view to its
spec signature, as native does for module members. runtime is what the runtime it was packaged
with provides (bake release check compares against it). On the device the core compares against the runtime the host actually links.
modules lists the first-party modules compiled into the package: the ones its bundle uses
(requires.modules), and no others (System modules).
An update that uses another one is refused (module \Clipboard`: the package does not include it`).
Escape hatches
nativeBuild(package.json"bakenative": { "package": { "nativeBuild": 1 } }, default 0): raise it when native behavior changes behind unchanged signatures. The package provides it, and bundles built from then on require at least it, so they are refused by older packages.runtime: when the app declares a runtime range, its bundles require it too (runtime 0.5.1 is outside the bundle's range >=0.4.0 <0.5.0).
Where it is checked
-
bake build. Everynative.<Module>.<member>the bundled sources use must exist in the package's schema, and everynative.<Module>must be a package module, a runtime module or a declared capability. Otherwise the build fails with the file and line. -
bake release check <bundle> --against <package>, in CI before an OTA release:bake release check dist/ios --against Norrow.xcframework # ✗ dist/ios/manifest.json must not ship to Norrow 1.0.0 (the device would reject it and run the embedded bundle): # native.NorrowShare.share: signature changed (bundle d6ac2802a0846f1f, package efede852341469fa)It exits with 1 when the bundle would be refused and prints every reason.
--jsonprints the result as JSON. On Android,--againstalso takes the package AAR or the app's APK (it readsassets/bakenative/<package id>/BakeNativePackage.json). On the device, Android'sBakeNativePackageprovides the first-party modules and native views the app links (the generatedBakeNativeAppModules/BakeNativeAppViewsfrombake native link), so a bundle that uses one the app lacks is refused. -
On the device. The Rust core decides, the same way on every platform: when a root opens a bundle it checks the runtime's half (renderer ops, events, style properties, runtime range) and refuses the bundle with the reasons. A package host also passes its own half to
bake_bundle_checkbefore it launches a downloaded bundle and keeps the embedded bundle when the answer is notok.
Reasons name each missing or changed item:
renderer batch op `mount-template`: this runtime no longer reads it
renderer batch op `create`: its fields changed (bundle ceedecf0869e4cc1, runtime 1b2c…)
event `tabselect`: this runtime no longer dispatches it
style property `gap`: this runtime no longer supports it
native.NorrowShare.share: the package no longer provides it
native.NorrowShare.share: signature changed (bundle d6ac2802a0846f1f, package efede852341469fa)
package: the bundle is for dev.bakenative.example.norrow, this package is dev.bakenative.example.showcase
nativeBuild: the bundle needs 2 or later, the package is 1The rules live in native/rust/crates/bake-runtime/src/compat.rs (device) and
packages/core/compat.mjs (bake release check); tests/compat/cases.json holds the cases
both must answer identically.
Renumbered renderer ops
A bundle's batches carry op tags, and its manifest the tag of each op name. When the runtime's
batch.oschema numbers an op differently, the core maps the bundle's tags to its own by name
while it reads, so renumbering or adding ops breaks nothing. Seed strings may only be appended;
reordering them, or changing the shared encoding, refuses every bundle built before.
Bundles from before requires
A manifest without requires is judged by what it carries: its batchDigest must equal the
runtime's exactly (it cannot be matched by name), and an old native block's package and
uses (member signatures, the same hashes as requires.native) are checked by name. Its
native.fingerprint is ignored. Rebuild such a bundle to get the by-name rules for the renderer
stream too.
The host contract (C ABI)
Include bakenative_package.h from native/rust/apple/Sources/CBakeNativeRust/include. The Rust core implements both calls for every platform.
| Function | Use |
|---|---|
bake_bundle_check(manifest, len, package, len, reason, cap, &written) | BAKE_PACKAGE_OK allows launch. BAKE_PACKAGE_UNSUPPORTED means launch the embedded bundle; reason holds the reasons, one per line. package is the package half of provides (package, nativeBuild, native) as JSON, or NULL for the runtime's half only. |
bake_runtime_provides(out, cap, &written) | the runtime's half as JSON (version, host protocol, batch ops, events, style properties) |
A package host builds its half from the modules it actually registers (<Module>.<member> →
signature, the same canonical line as above), its package id and nativeBuild:
- iOS:
BakeNativePackage.check(update:)(anduse(update:),bundle(preferring:)) first checks the bundle files (manifest, Hermes bytecode version), then callsbake_bundle_checkwithBakeNativePackage.provides, built live from the package's modules. A rejected update leaves the embedded bundle; the reason names each missing or changed item.schemaDriftwarns when the compiled modules differ from the signatures inBakeNativePackage.json(a stalenative-modules.json). - Android:
dev.bakenative.BakeNativePackage(fromAssets/fromDirectory,check,use,bundle) calls the same function over JNI (BakeNativeBundleChecker.Core). Android has no native module registry yet, so its provides take the signatures fromBakeNativePackage.jsonprovides.native.
Runtime range
A package declares the runtimes it runs on (runtime, by default the series it was built with:
>=0.0.1 <0.1.0). When the host links a runtime outside that range, the package does not start:
makeViewController() shows the reason and logs
[BakeNative] package cannot start: Norrow needs BakeNative runtime >=0.0.1 <0.1.0 (built with 0.0.1); this app links BakeNative.xcframework 0.2.0 ....
BakeNativeRuntime.version is the linked runtime's version.
6. Third-party libraries
Two packages that each carry the same third-party library (Lottie, Firebase, OkHttp, SQLite) break
one host: duplicate symbols when a static iOS host links them, two copies of one ObjC class in a
dynamic one, resource and manifest merge conflicts on Android, and a crash when two
libc++_shared.so from different NDKs meet. So a package declares every third-party library it
uses, and chooses per library how the host gets it:
| Mode | The host gets | Possible for |
|---|---|---|
shared (default) | one copy, linked by the host; every package states the versions it accepts | everything |
isolated | each package's own copy, renamed into the package (relocated Java/Kotlin packages, renamed .so, prefixed C symbols) | Java/Kotlin, .so, C. Not Swift modules or ObjC classes: a process has one module or class of each name |
Third-party code a package carries without declaring it is a packaging error in either mode.
Declare them
In bakenative.package of the app's package.json:
{
"bakenative": {
"package": {
"name": "Norrow",
"id": "dev.bakenative.example.norrow",
"android": { "package": "dev.bakenative.example.norrow", "resourcePrefix": "norrow_", "soPrefix": "libnorrow" },
"thirdParty": [
{
"name": "lottie",
"version": "^6.4.0",
"mode": "shared",
"android": { "packages": ["com.airbnb.lottie"], "maven": "com.airbnb.android:lottie" },
"ios": { "language": "swift", "modules": ["Lottie"] }
},
{
"name": "sqlite",
"version": "3.45.1",
"mode": "isolated",
"platforms": ["android", "ios"],
"android": { "so": ["libsqlite3.so"] },
"ios": { "language": "c", "symbols": ["sqlite3_"] }
}
]
}
}
}| Field | Meaning | Default |
|---|---|---|
name | the library; the host check matches packages by it | required |
version | the versions the package works with: >=6.4.0 <7.0.0, ^6.4.0, ~6.4.1, 6.4.x, 6.4.1, alternatives with || | required |
mode | shared or isolated | shared |
platforms | android, ios | the platforms with a block below |
android.packages | its Java/Kotlin packages (original names) | one of packages / so |
android.so | its .so files (original names) | |
android.maven | the coordinate the host adds for a shared library (informational) | none |
ios.language | swift, objc or c | required for iOS |
ios.modules / ios.classes / ios.symbols | its Swift/clang modules, ObjC class prefixes, C symbol prefixes | the one for its language |
android says where the package's own Android code lives; everything outside it is third-party:
| Field | Meaning | Default |
|---|---|---|
package | Java/Kotlin package prefix of its classes and its manifest namespace | the package id |
resourcePrefix | prefix of every Android resource name (AGP resourcePrefix) | <name>_, lowercased |
soPrefix | prefix of its .so files; isolated copies are <soPrefix>_<name>.so | lib<name>, lowercased |
A library may be declared once per platform, so it can be isolated on Android and shared on iOS
(two entries, each with its own platforms). bake package and both checks below refuse a
declaration they cannot use: no identity, an unreadable range, or isolated for Swift / ObjC.
BakeNativePackage.json carries thirdParty and android, so a host checks packages without their
sources.
Check a package: bake package check
bake package check norrow.aar # reads assets/bakenative/<id>/BakeNativePackage.json, else --root's package.jsonThe check reads the AAR itself (zip, ELF, manifest XML; no Android tools) and fails on:
| Code | What it found | Fix |
|---|---|---|
undeclared-classes | classes (in classes.jar or a packed libs/*.jar) outside the package's Java package that no entry claims | declare the library; shared: compileOnly, isolated: relocate under the package |
undeclared-so | a .so outside soPrefix, or one a package .so needs (DT_NEEDED) that is not the package's, the runtime's, a system library or a shared declaration | declare it; isolated: rename it |
shared-bundled | a shared library's classes, .so or manifest components inside the AAR | make the dependency compileOnly; the host links one copy |
isolated-not-renamed | an isolated library under its original package or file name, or a .so linked against the original name | relocate (Shadow / jarjar), or rename the .so and its SONAME |
runtime-bundled | classes in dev.bakenative.*, or libbakenative.so / libbakehermes.so / libhermesvm.so | depend on the runtime with compileOnly |
cxx-shared-ndk | a libc++_shared.so from an NDK outside the runtime's series (read from its .note.android.ident), or without the note | build with the runtime's NDK (ndkVersion = "28.2.13676358", range >=28.0.0 <29.0.0) |
soname | a package .so whose SONAME is not its file name | -Wl,-soname,<file> |
resource-prefix | a resource (file, values entry or styleable attr) not starting with resourcePrefix | rename; set AGP resourcePrefix |
asset-path | assets outside assets/bakenative/<id>/ | move them |
manifest-namespace | a manifest package outside the package's Java package | namespace = ... |
manifest-application | <application> attributes (name, theme, icon, allowBackup, …) | remove: the host owns <application> |
manifest-override | tools:replace / tools:remove / tools:node | remove: a package does not rewrite the host's manifest |
manifest-component | an activity, service, receiver or provider class outside the package | declare its library |
provider-authority | an authority without ${applicationId} and the package's name | ${applicationId}.<package>.<name> |
manifest-permission | a <permission> outside the package | name it under the package |
min-sdk | minSdkVersion above the runtime's (29) | lower it |
kotlin-module | META-INF/<module>.kotlin_module without the package name (two app_release modules fail the host build) | set the Kotlin moduleName |
proguard-global | consumer rules with global options (-dontobfuscate, -repackageclasses, …) | keep to -keep rules for the package |
Warnings (exit 0): a .so for an ABI the runtime does not ship, a .so that exports symbols
besides JNI that no other package .so links against (statically linked C code shows up there;
-fvisibility=hidden), un-namespaced <meta-data>, a jar packed into the AAR.
✗ sneaky.aar (Sneaky, dev.bakenative.example.sneaky): 1/2 classes own, 3 .so, 3 resources
✗ [undeclared-classes] classes.jar: com.acme.vendor.* (1 file, e.g. com/acme/vendor/Vendor.class) is not Sneaky's code (dev.bakenative.example.sneaky.*) and no thirdParty entry claims it
fix: declare it in package.json "bakenative.package.thirdParty" (…). shared: drop its classes from the AAR (compileOnly / no jniLibs copy) so the host links one copy. isolated: rename it into Sneaky's namespace (…)
✗ [cxx-shared-ndk] jni/arm64-v8a/libc++_shared.so comes from NDK r27-beta1 (27.0.0); the shared runtime fixes NDK >=28.0.0 <29.0.0. …bake package --target android (planned, below) will run the same check on the AAR it writes before it is written.
Check a host: bake package host-check
bake package host-check norrow.aar showcase.aar dist/ios-package/ [--provide lottie=6.5.0] [--platform android]Each argument is an AAR (its embedded BakeNativePackage.json, plus the package check), an
BakeNativePackage.json or its directory, or an app directory. Per platform and library, the shared
ranges must overlap: the host links one version inside all of them (--provide checks a version
the host already links). When they do not overlap, the error names each package's range and the way
out: make all but one isolated or, for Swift / ObjC, align the versions. It also fails when two
packages share an id, overlapping Java packages, a resource or .so prefix, a .so file name, a
provider authority, a Kotlin module file or a manifest namespace.
✗ 2 packages in one host: Alpha, Gamma
android vendor: no common version — Alpha >=1.2.0 <2.0.0, Gamma ^2.1.0
✗ android vendor: the shared version ranges do not overlap, so the host cannot link one copy:
Alpha: >=1.2.0 <2.0.0
Gamma: ^2.1.0
Align the ranges, or make all but one of them "mode": "isolated" (…)tests/package-third-party builds such packages with AGP and the NDK (run.mjs; the test runs it
with BAKE_ANDROID_E2E=1).
The iOS check (contract)
The same rules for <App>.xcframework, checked on macOS by bake package --target ios (planned;
BakeNativePackage.json already carries the declarations, and host-check already checks the iOS
ranges):
- Swift modules: every
.swiftmodule/.swiftinterfacein the xcframework is the package's own module, and every module a.swiftinterfaceimports is the package's, a runtime module (BakeNative), an SDK module or asharedlibrary'sios.modules. Asharedlibrary's module inside the xcframework isshared-bundled; any other foreign module isundeclared-module. Swift and ObjC libraries cannot beisolated. - ObjC classes: every
_OBJC_CLASS_$_<Name>the archive defines (nm -gU, each slice) is the package's own (its module's mangling for Swift classes, its prefix for ObjC). One with asharedlibrary'sios.classesprefix isshared-bundled; any other isundeclared-objc-class. - C symbols: every defined global symbol is the package's, or, for an
isolatedC library, carries the package's prefix (norrow_sqlite3_open, notsqlite3_open): anios.symbolsprefix without it isisolated-not-renamed, in asharedlibraryshared-bundled. Undefined references to asharedlibrary's symbols are expected: the host links it. - Linking: packages stay static (or mergeable); a dynamic package that embeds a library a second package also embeds is the duplicate-class case and fails the same way.
- Errors use the Android check's codes and
message/fixshape.
Android (planned)
The same contract, as Android libraries:
- The runtime AAR (
dev.bakenative:bakenative, Android AAR): onelibbakenative.so(Rust core and Hermes linked statically withc++_staticand hidden symbols, so it never clashes with a React Native host'slibhermes.so,libjsi.soorlibc++_shared.so) plus the Kotlin host. bake package --target android→<app>.aar: the app's Kotlin modules, the bundle underassets/bakenative/<package id>/(namespaced per package),BakeNativePackage.json, and one entry point:Norrow.view(context)/Norrow.fragment(),Norrow.prewarm(context),Norrow.use(update).- The same requires and provides: member signatures from the Kotlin module schema with the same
canonical lines, checked by the same Rust core (
bake_bundle_checkover JNI), so onebake release checkserves both platforms.
Limits
- The JS check reads
native.<Module>.<member>in the source text; the binding must be namednative. native-modules.jsonis written by running the package. The package compares it with the compiled modules when its first screen opens and logs[BakeNative] warning: ...when they differ; extracting it at build time is planned.- Capabilities are checked by name, not by signature.
- Third-party libraries are declared, never carried unannounced: 6. Third-party libraries.