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.
1. Package the project
Section titled “1. Package the project”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.
bun run nuib package # every configured platformbun run nuib package --platform android --out dist # one platform, another output directoryThe command does three things:
- Reads the contract: every
registerSurfacecall and its props type. - Generates typed Swift and Kotlin code from it: one type per surface, plus the entry type
ShopReact. - Builds one artifact per platform. It holds the engine, your bundled React code and the generated code.
What it writes
Section titled “What it writes”For an artifact named ShopReact, the output directory is .nuib/out in the project:
manifest.jsonios/ShopReact/Package.swift SwiftPM package: one product, ShopReactios/ShopReact/ShopReact.xcframework dynamic framework; module ShopReactandroid/maven/<group>/<artifact>/<version>/ AAR and POM, a local Maven repositorysymbols/ios/<slice>/ShopReact.framework.dSYM debug symbols of each iOS slicesymbols/android/<abi>/*.so unstripped libraries of each ABIsymbols/<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.jsonrecords 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 thatnuib publishaccepts..nuib/carries its own.gitignore. Outputs and caches never reach git.
Options
Section titled “Options”| 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.
Variants: release and dev
Section titled “Variants: release and dev”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.
2. Publish a version
Section titled “2. Publish a version”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":
"registry": "../nuib-registry"bun run nuib packagebun run nuib publish # to brownfield.registrybun 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.
Registry layout
Section titled “Registry layout”Inside <registry>:
registry.json index of artifacts and versionsmaven/<group path>/<artifact>/maven-metadata.xmlmaven/<group path>/<artifact>/<version>/ the AAR and its POMShopReact/<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.jsswiftpm/Package.swiftis a local Swift package: its binary target points at the zip beside it, by path.checksum.txtholds the checksum that a binary target with a URL would need.nuib publishwrites these files to the registry directory; it does not upload the zip anywhere.registry.jsonlists 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.
What nuib publish refuses, and why
Section titled “What nuib publish refuses, and why”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.
Versions follow the contract
Section titled “Versions follow the contract”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.
3. Hand it to the native team
Section titled “3. Hand it to the native team”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 ShopReactWith Gradle:
dependencyResolutionManagement { repositories { google() mavenCentral() maven { url = uri("<registry>/maven") } }}android { defaultConfig { ndk { abiFilters += "arm64-v8a" } }}dependencies { implementation("com.example:shop-react:0.1.0")}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.
Test a local build in the native app
Section titled “Test a local build in the native app”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:
bun run nuib link ../native-app # package the release variant and point the app at itbun run nuib link --dev ../native-app # the same with the dev variantbun run nuib unlink ../native-app # undonuib 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. Otherwisenuib linkrefuses. - Without
--platform,nuib linklinks the one platform thebrownfieldkey configures, and iOS when it configures both. Pass--platform androidfor the Android app. <native app>is the app’s directory: for iOS, the one with the.xcodeproj; for Android, the one withsettings.gradleorsettings.gradle.kts.- With the dev variant, start the dev server with
nuib devin the React project. The app tries it at launch. - Links are recorded in
.nuib/links.json.nuib unlinkremoves exactly whatnuib linkadded.
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:
bun run nuib packagebun run nuib check --max-size-increase 500KB- The limit takes bytes (
2048),KBorMB, 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 checkexits with 32. nuib checknever builds. Without a package in.nuib/outit skips the size comparison.