Skip to content
Preview: packages are not published yet.

Package and publish

The native app consumes your React project as one binary dependency per platform. nuib package builds it. nuib publish stores it as a version the native team can pin. This how-to is for the React team and CI.

Run nuib package in the React project. It reads the brownfield key of package.json and packages every platform that has a section there: an XCFramework in a SwiftPM package for iOS, an AAR in a Maven layout for Android.

Terminal window
bun run nuib package # every configured platform
Terminal window
bun run nuib package --platform android --out dist # one platform, another output directory

The command does three things:

  1. Reads the contract: every registerSurface call and its props type.
  2. Generates typed Swift and Kotlin code from it: one type per surface, plus the entry type ShopReact.
  3. Builds one artifact per platform. It holds the engine, your bundled React code and the generated code.

For an artifact named ShopReact, the output directory is .nuib/out in the project:

.nuib/out
manifest.json
ios/ShopReact/Package.swift SwiftPM package: one product, ShopReact
ios/ShopReact/ShopReact.xcframework dynamic framework; module ShopReact
android/maven/<group>/<artifact>/<version>/ AAR and POM, a local Maven repository
symbols/ios/<slice>/ShopReact.framework.dSYM debug symbols of each iOS slice
symbols/android/<abi>/*.so unstripped libraries of each ABI
symbols/<platform>/main.hbc.map, main.js source map of the app code
  • The binaries inside the artifact are stripped. Their debug symbols are written beside the artifact, under symbols/, never inside it.
  • manifest.json records the artifact’s name, version and variant, the contract, the sizes and the SHA-256 of every packaged file. It is written last, so a failed run leaves no manifest and nothing that nuib publish accepts.
  • .nuib/ carries its own .gitignore. Outputs and caches never reach git.
Option Default Use
--platform ios|android|all Every platform with a section in the key What to package
--variant release|dev release Which variant to build. See below.
--out <dir> .nuib/out, or .nuib/out-dev for dev The output directory. An existing directory must be empty or one that nuib package created.
--cache-dir <dir> .nuib/cache Caches, work files and logs. It must be outside --out.
--project <dir> The current directory The React project
--ios-slices simulator,device Both The iOS slices to build. Both are arm64; there is no x86_64 simulator slice.
--android-abis <list> arm64-v8a The Android ABIs to build

The first run compiles the native engine and takes a few minutes. After that, caches skip every layer that did not change. A change to your React code rebuilds only the bundled content, as long as the contract stays the same and the code uses the same parts of the framework. The command prints HIT or MISS for each layer. While you try things, --ios-slices simulator builds only the iOS simulator slice, so the first iOS run builds one slice instead of two. The dev variant (--variant dev, also used by nuib dev and nuib link --dev) has its own engine build, so its first run is slow too.

One project gives two artifacts. They have the same name, the same Maven coordinate and the same public API.

release (default) dev
Who uses it The native app, in every build configuration, Debug included Someone who wants Fast Refresh inside the real app
How the app gets it Its normal dependency nuib dev ios, nuib dev android or nuib link --dev
At launch Loads the content packaged inside it Tries the dev server at http://localhost:<dev.port>. Without an answer it loads the packaged content.
Network Never Only that dev server
Published Yes Never. nuib publish refuses it.

You rarely build the dev variant by hand. nuib dev ios and nuib dev android build it for the session, as Run and develop shows.

nuib publish takes what nuib package wrote and stores it as one version in a registry. The registry is a directory on this machine. Nothing leaves the machine: there is no network, no credentials and no remote. A CI job can later copy or serve the directory. Serving it is not part of nuib.

Set the registry once in the brownfield key. The path is relative to the project. Add this inside "brownfield":

package.json
"registry": "../nuib-registry"
Terminal window
bun run nuib package
Terminal window
bun run nuib publish # to brownfield.registry
Terminal window
bun run nuib publish --registry ../other # to another directory
Option Default Use
--registry <dir> brownfield.registry The registry directory
--force Off Replace a version that is already published
--out <dir> .nuib/out What nuib package wrote
--project <dir> The current directory The React project

The exit code is 0 when the version is published. It is 1 when the command refuses or fails, and the reason is printed.

Inside <registry>:

registry.json index of artifacts and versions
maven/<group path>/<artifact>/maven-metadata.xml
maven/<group path>/<artifact>/<version>/ the AAR and its POM
ShopReact/<version>/
manifest.json the packaged manifest
size-report.txt sizes, for people
size-report.json sizes, for tools
swiftpm/Package.swift the SwiftPM package
swiftpm/ShopReact.xcframework.zip the XCFramework
swiftpm/checksum.txt the SwiftPM checksum of the zip
symbols/ios/<slice>/ShopReact.framework.dSYM
symbols/android/<abi>/<library>.so
symbols/<platform>/main.hbc.map, main.js
  • swiftpm/Package.swift is a local Swift package: its binary target points at the zip beside it, by path. checksum.txt holds the checksum that a binary target with a URL would need. nuib publish writes these files to the registry directory; it does not upload the zip anywhere.
  • registry.json lists each published version with its platforms, its contract hash and the time of publication.
  • One registry holds one line of versions per artifact name. A version is published once, with the platforms of the project that packaged it. The registry writes its own .gitignore.

Every check runs before anything is written. A refused publish leaves the registry unchanged.

It refuses Why What to do
A publish while a link is recorded in .nuib/links.json A linked native app builds from this machine’s local artifact. Run nuib unlink <app>. The message names the app.
A version that is already published A published version must not change under the apps that pin it. Raise brownfield.version, or pass --force to replace it.
A package that does not match the current sources: another name, version or contract You would publish something other than what the sources say. Run nuib package again.
The dev variant The dev variant contacts a dev server. It is never shipped. Run nuib package without --variant dev.
Files that differ from the manifest: changed, added or removed after packaging The manifest records the SHA-256 of every packaged file. The published files must be the ones that were built and checked. Run nuib package again. Every problem is listed.
A version that fails nuib check against the last published version A breaking change to the contract needs a version that says so. Raise the version as the report proposes. See below.

Without a registry, the command stops with No registry: add "registry" to the brownfield key … or pass --registry <dir>. Without a package, it stops with No packaged manifest at …: run nuib package first.

You set the version in brownfield.version. nuib does not pick it for you, but it checks it. nuib publish runs nuib check, which compares your contract with the last published version and says which level the change needs.

Change Needs From 1.2.3 From 0.1.0
breaking, for example a new required prop major 2.0.0 0.2.0
additive, for example a new surface minor 1.3.0 0.1.1
internal, only code inside components patch 1.2.4 0.1.1

While the major is 0, the minor is the breaking position, and the patch covers additions and internal changes.

nuib publish refuses a configured version that is lower than the last published one, and a breaking change without a major bump (0.x: without a minor bump). A smaller bump than an addition or internal change needs, or a larger bump than needed, is only a warning.

“The last published version” is the highest published version below the one you publish. A 1.4.1 maintenance release is compared with 1.4.0, even when 2.0.0 is already published.

A contract that cannot be read and a type error also fail the check. Check the contract lists every kind of change and its impact. Run nuib check on each pull request to see the proposal before you publish.

Give the native team access to the registry directory and tell them the version. They add one dependency per platform.

With SwiftPM:

Add as a local package:
<registry>/ShopReact/<version>/swiftpm
Link the product:
ShopReact
In Swift:
import ShopReact

Tell them these facts too:

What Value for this example
Kotlin package of the generated code com.example.shopreact: android.group, then name in lower case
Entry point ShopReact.start, called once at app start
One type per surface PointsHistory, with its props as typed parameters
Symbols for crash reports <registry>/ShopReact/<version>/symbols
What changed The nuib check report and size-report.txt

When you serve the registry from a URL, the iOS package needs the checksum. The comment at the top of the published Package.swift has the ready binaryTarget line with the checksum from checksum.txt.

The native team’s side is described in the Native app guide.

For daily work, nuib dev ios and nuib dev android put your project in the native app for one session. Use nuib link when you need more than that: for example to try an unpublished release build in the app before you publish it.

Run these in the React project:

Terminal window
bun run nuib link ../native-app # package the release variant and point the app at it
Terminal window
bun run nuib link --dev ../native-app # the same with the dev variant
Terminal window
bun run nuib unlink ../native-app # undo

nuib link runs nuib package and then makes the app resolve the artifact from your local output. It does not edit the app’s project or build files.

Platform What nuib link changes How to build the app
iOS Adds the local package to the Xcode project’s own workspace, <App>.xcodeproj/project.xcworkspace. It overrides the dependency with the same name. On the command line, build with -workspace <App>.xcodeproj/project.xcworkspace. A build with -project ignores the override.
Android Writes one Gradle init script in the Gradle user home, under init.d/. It acts only on that app’s build. Build as usual, for example ./gradlew :app:installDebug. The build prints an nuib link: line that names the local repository.
  • The app must already depend on the artifact: a Swift package named ShopReact, or the Maven coordinate in a build file. Otherwise nuib link refuses.
  • Without --platform, nuib link links the one platform the brownfield key configures, and iOS when it configures both. Pass --platform android for the Android app.
  • <native app> is the app’s directory: for iOS, the one with the .xcodeproj; for Android, the one with settings.gradle or settings.gradle.kts.
  • With the dev variant, start the dev server with nuib dev in the React project. The app tries it at launch.
  • Links are recorded in .nuib/links.json. nuib unlink removes exactly what nuib link added.

Every published version carries size-report.txt and size-report.json. They give the weight of the artifact as packaged, and the difference from the previous published version. The first version has sizes only.

The report has one row per iOS slice and per Android ABI, with a difference row under each, split in four layers and a total. It also gives the size of the AAR file.

Layer What it is Changes when
engine The native runtime The engine’s version or native code changes
framework The React framework code, compiled to native code Your code starts to use other parts of the framework
facade The generated Swift and Kotlin types The contract changes
content Your bundled React code Your code changes

You can see a size jump before you publish. nuib check compares the sizes of the package in .nuib/out with the last published version, and can fail on a limit:

Terminal window
bun run nuib package
Terminal window
bun run nuib check --max-size-increase 500KB
  • The limit takes bytes (2048), KB or MB, or a percentage (5%).
  • It applies to what ships: the binary of each iOS slice, the AAR and the runtime library of each ABI.
  • When a figure grows by more than the limit, nuib check exits with 32.
  • nuib check never builds. Without a package in .nuib/out it skips the size comparison.