Installation
copilot plugin marketplace add samueltauil/skills-hub
copilot plugin install react-native-brownfield-migration@skills-hub
Works with GitHub Copilot CLI and VS Code (enable chat.plugins.enabled).
Plugin react-native-brownfield-migration v1.0.0 follows the Agent Plugins spec.
gh skills-hub install react-native-brownfield-migration Don't have the extension? Run gh extension install samueltauil/skills-hub first.
Download and extract to your repository:
.github/skills/react-native-brownfield-migration/ Extract the ZIP to .github/skills/ in your repo. The folder name must match react-native-brownfield-migration for Copilot to auto-discover it.
Skill Files (14)
SKILL.md 8.0 KB
---
name: react-native-brownfield-migration
description: Implements an accepted incremental brownfield migration from native iOS or Android to React Native or Expo using @callstack/react-native-brownfield. Use after the brownfield path has been selected, when setting up the integration, packaging XCFramework or AAR artifacts, or adding React Native surfaces to native hosts.
license: MIT
---
# Migrating to React Native
Use this skill only after the decision to adopt brownfield migration has been made. When the user is still choosing between brownfield, greenfield, a checkpoint-based path, defer, or no migration, use [assess-react-native-migration](../assess-react-native-migration/SKILL.md) first.
## Overview
Prescriptive workflow for incremental adoption of React Native in existing native apps using `@callstack/react-native-brownfield`, from initial setup through phased host integration.
- Expo track
- Bare React Native track
Use one track per task unless the user explicitly asks for migration or comparison.
## Migration Strategy
Use this strategy for brownfield migration planning and execution:
1. Assess app state and select Expo or bare path.
2. Perform initial setup with `@callstack/react-native-brownfield`.
3. Package RN artifacts (`XCFramework`/`AAR`) from the RN source app.
4. Integrate one RN surface into the host app and validate startup/runtime.
5. Repeat integration by feature/screen for incremental rollout.
## Agent Guardrails (Global)
Apply these rules across all reference files:
1. Select one path first (Expo or bare) and do not mix steps.
2. Use placeholders from the docs (`<framework_target_name>`, `<android_module_name>`, `<registered_module_name>`) and resolve from project files.
3. Validate each packaging command before moving to host integration.
4. Run `npx brownfield <command> --help` before relying on any flag table in these references; help output wins.
5. Write stable project settings once into `brownfield.config.*` instead of repeating flags — see [cli-and-config.md][cli-and-config].
6. Prefer official docs for long platform snippets and CLI option details.
7. Keep host apps isolated from direct React Native APIs when possible (facade approach).
8. For startup/runtime verification, use `agent-device` to open the host app, navigate to the RN surface, capture snapshots/screenshots, and collect device evidence. If it is missing and verification needs it, install it through the environment's approved/trusted path or ask the user to install or enable it.
## Canonical Docs
- [Quick Start](https://oss.callstack.com/react-native-brownfield/docs/getting-started/quick-start.md)
- [Expo Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/expo.md)
- [iOS Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/ios.md)
- [Android Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/android.md)
- [Brownfield CLI](https://oss.callstack.com/react-native-brownfield/docs/cli/brownfield.md)
- [Configuration](https://oss.callstack.com/react-native-brownfield/docs/api-reference/configuration.md)
- [Guidelines](https://oss.callstack.com/react-native-brownfield/docs/guides/guidelines.md)
- [Troubleshooting](https://oss.callstack.com/react-native-brownfield/docs/guides/troubleshooting.md)
## Path Selection Gate (Must Run First)
Before selecting any reference file, classify the project:
1. If no React Native app exists yet, use Expo creation path:
- [expo-create-app.md][expo-create-app] -> [expo-quick-start.md][expo-quick-start]
2. If React Native app exists, inspect `package.json` and `app.json`:
- Expo if `expo` is present or Expo plugin workflow is requested.
- Bare RN if native folders and direct RN CLI workflow are used without Expo path requirements.
3. If still unclear, ask one disambiguation question.
4. Continue with exactly one path.
## When to Apply
Reference this package when:
- Implementing an accepted incremental migration from native-only apps to React Native or Expo
- Creating brownfield integration flows for Expo or bare React Native projects
- Performing initial setup with `@callstack/react-native-brownfield`
- Generating iOS XCFramework artifacts from a React Native app
- Generating and publishing Android AAR artifacts from a React Native app
- Integrating generated artifacts into host iOS/Android apps
## Quick Reference
| File | Description |
|------|-------------|
| [quick-start.md][quick-start] | Shared preflight and mandatory path-selection gate |
| [cli-and-config.md][cli-and-config] | CLI commands, full flag sets, config file, artifact layout, codegen side effects |
| [runtime-api.md][runtime-api] | Host <-> RN API surface (JS, Swift, Kotlin) and reference apps |
| [expo-create-app.md][expo-create-app] | Scaffold a new Expo app before Expo brownfield setup |
| [expo-quick-start.md][expo-quick-start] | Expo plugin setup and packaging readiness |
| [expo-ios-integration.md][expo-ios-integration] | Expo iOS packaging and host startup integration |
| [expo-android-integration.md][expo-android-integration] | Expo Android packaging, publish, and host integration |
| [bare-quick-start.md][bare-quick-start] | Bare React Native baseline setup |
| [bare-ios-xcframework-generation.md][bare-ios-xcframework-generation] | Bare iOS XCFramework generation |
| [bare-android-aar-generation.md][bare-android-aar-generation] | Bare Android AAR generation and publish |
| [bare-ios-native-integration.md][bare-ios-native-integration] | Bare iOS host integration |
| [bare-android-native-integration.md][bare-android-native-integration] | Bare Android host integration |
## Problem -> Skill Mapping
| Problem | Start With |
|---------|------------|
| Need migration path decision first | [assess-react-native-migration](../assess-react-native-migration/SKILL.md) |
| Need Expo vs bare path decision | [quick-start.md][quick-start] |
| Need a CLI flag, the config file shape, or the artifact paths | [cli-and-config.md][cli-and-config] |
| Need a host <-> RN API name, signature, or a working example app | [runtime-api.md][runtime-api] |
| Need shared state between host and RN, or typed RN -> native navigation | `brownie` / `brownfield-navigation` skills |
| Need to create a new Expo app for brownfield | [expo-create-app.md][expo-create-app] |
| Need Expo brownfield setup and plugin wiring | [expo-quick-start.md][expo-quick-start] |
| Need Expo iOS brownfield integration | [expo-ios-integration.md][expo-ios-integration] |
| Need Expo Android brownfield integration | [expo-android-integration.md][expo-android-integration] |
| Need bare RN baseline setup | [bare-quick-start.md][bare-quick-start] |
| Need bare RN iOS XCFramework generation | [bare-ios-xcframework-generation.md][bare-ios-xcframework-generation] |
| Need bare RN Android AAR generation/publish | [bare-android-aar-generation.md][bare-android-aar-generation] |
| Need bare RN iOS host integration | [bare-ios-native-integration.md][bare-ios-native-integration] |
| Need bare RN Android host integration | [bare-android-native-integration.md][bare-android-native-integration] |
## Related Skills
- [Assess React Native migration](../assess-react-native-migration/SKILL.md) before selecting the migration path.
- `brownie` (shared host <-> RN state) and `brownfield-navigation` (typed RN -> native navigation) ship from another repo: invoke them by name, and fall back to the canonical docs if they are not installed.
[quick-start]: references/quick-start.md
[cli-and-config]: references/cli-and-config.md
[runtime-api]: references/runtime-api.md
[expo-create-app]: references/expo-create-app.md
[expo-quick-start]: references/expo-quick-start.md
[expo-ios-integration]: references/expo-ios-integration.md
[expo-android-integration]: references/expo-android-integration.md
[bare-quick-start]: references/bare-quick-start.md
[bare-ios-xcframework-generation]: references/bare-ios-xcframework-generation.md
[bare-android-aar-generation]: references/bare-android-aar-generation.md
[bare-ios-native-integration]: references/bare-ios-native-integration.md
[bare-android-native-integration]: references/bare-android-native-integration.md
openai.yaml 0.5 KB
interface:
display_name: "React Native Brownfield Migration"
short_description: "Incremental migration to React Native or Expo using @callstack/react-native-brownfield with strategy and phased integration steps"
default_prompt: "Use $react-native-brownfield-migration to plan and execute incremental migration from native iOS/Android to React Native or Expo using @callstack/react-native-brownfield, including initial setup, packaging, and phased host integration."
bare-android-aar-generation.md 4.2 KB
---
title: Bare Android AAR Generation
impact: CRITICAL
tags: react-native, brownfield, bare, android, aar
---
# Skill: Bare Android AAR Generation
Package a bare React Native app into an Android AAR and publish it for native host consumption.
## Quick Command
```bash
npx brownfield package:android --variant release --module-name <android_module_name>
npx brownfield publish:android --module-name <android_module_name>
```
`--module-name` follows the project's own spelling: a Gradle path such as `:BrownfieldLib` for a
module declared in `settings.gradle`, or a plain name such as `brownfieldlib`. For the rest of the
options and for recording `moduleName`/`variant` in `brownfield.config.*`, see
[cli-and-config.md](./cli-and-config.md).
## When to Use
- Building Android artifact from bare RN app
- Publishing AAR for host app dependency resolution
## Prerequisites
- [bare-quick-start.md](./bare-quick-start.md) completed
- Dedicated Android library module exists (`com.android.library`)
- Brownfield Gradle plugin configured
- RN and Hermes dependency versions aligned with `package.json`
## Step-by-Step Instructions
```text
Progress checklist:
- [ ] Library module verified
- [ ] Plugin + autolinking configured
- [ ] Publishing configured
- [ ] package:android succeeds
- [ ] publish:android succeeds
- [ ] Host app resolves Maven coordinate
```
1. Verify target module is a library module and will be passed as `--module-name`.
2. Ensure module plugins include:
- `com.android.library`
- `org.jetbrains.kotlin.android`
- `com.facebook.react`
- `com.callstack.react.brownfield` (classpath `com.callstack.react:brownfield-gradle-plugin:<version>`,
or `useLocalGradlePlugin` on the Expo path)
- `maven-publish`
The Brownfield plugin discovers transitive native dependencies for you
(`experimentalIncludeTransitiveDependencies`, on by default), so do not hand-declare the androidx
dependencies of RN libraries in this module.
3. Ensure autolinking is enabled in module:
```kotlin
react {
autolinkLibrariesWithApp()
}
```
4. Add/verify facade bootstrap class in artifact module (host app should call only this facade):
```kotlin
object ReactNativeHostManager {
fun initialize(application: Application, onJSBundleLoaded: OnJSBundleLoaded? = null) {
loadReactNative(application)
val packageList = PackageList(application).packages
ReactNativeBrownfield.initialize(application, packageList, onJSBundleLoaded)
}
}
```
5. Package AAR:
- `npx brownfield package:android --variant release --module-name <android_module_name>`
6. Publish to Maven local:
- `npx brownfield publish:android --module-name <android_module_name>`
7. Validate host app resolves `groupId:artifactId:version` with `mavenLocal()` enabled.
If the library module declares product flavors, the host must resolve them —
`missingDimensionStrategy("<dimension>", "<flavor>")` in the host app module, or
`missingDimensionStrategies` in the Expo plugin options. See the Troubleshooting docs.
## Stop Conditions
Proceed only if:
- package and publish commands exit with code `0`
- host app resolves published coordinate
## If Failed
- Re-check module type (`com.android.library`) and module-name flag
- Re-check plugin configuration and `maven-publish`
- Clean/rebuild Android project and retry package/publish
- Do not proceed to runtime integration until coordinate resolution passes
## Canonical Docs
- [Android Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/android.md)
- [Brownfield CLI](https://oss.callstack.com/react-native-brownfield/docs/cli/brownfield.md)
- [Guidelines](https://oss.callstack.com/react-native-brownfield/docs/guides/guidelines.md)
- [Troubleshooting](https://oss.callstack.com/react-native-brownfield/docs/guides/troubleshooting.md)
## Common Pitfalls
- Using app module instead of library module for packaging
- RN/Hermes dependency mismatch vs `package.json`
- Missing `mavenLocal()` in host dependency resolution
## Related Skills
- [cli-and-config.md](./cli-and-config.md) - Full CLI option set, config file, artifact layout
- [bare-quick-start.md](./bare-quick-start.md) - Bare setup prerequisites
- [bare-android-native-integration.md](./bare-android-native-integration.md) - Bare Android host integration
bare-android-native-integration.md 3.2 KB
---
title: Bare Android Native Integration
impact: HIGH
tags: react-native, brownfield, bare, android, aar
---
# Skill: Bare Android Native Integration
Consume published bare RN AAR in host Android app and verify runtime rendering.
## Quick Command
```kotlin
// settings.gradle.kts
repositories { mavenLocal() }
// app/build.gradle.kts
dependencies { implementation("<groupId>:<artifactId>:<version>") }
```
## When to Use
- Consuming locally published AAR from bare RN artifact module
- Wiring host startup and rendering for RN-powered screens
## Prerequisites
- [bare-android-aar-generation.md](./bare-android-aar-generation.md) completed
- AAR published to local Maven
- Host app Gradle sync is healthy
## Agent-Assisted Verification
Use `agent-device` after the host build succeeds. Read the `agent-device` skill or CLI help when available before exact commands. If it is missing and verification needs it, install it through the environment's approved/trusted path or ask the user to install or enable it. Then open the host app, navigate to the RN surface, capture snapshots/screenshots, and collect logs for runtime behavior.
## Step-by-Step Instructions
```text
Progress checklist:
- [ ] Add mavenLocal in host repositories
- [ ] Add dependency coordinate
- [ ] Initialize host runtime
- [ ] Render RN module
```
1. Add `mavenLocal()` in host `dependencyResolutionManagement` repositories.
2. Add published dependency coordinate in app module.
3. Initialize runtime before RN UI creation:
```kotlin
ReactNativeHostManager.initialize(this.application) {
println("JS bundle loaded")
}
```
4. Render RN UI:
- `ReactNativeFragment.createReactNativeFragment("<registered_module_name>", initialProps)`
- or `ReactNativeBrownfield.shared.createView(activity, "<registered_module_name>", reactDelegate, launchOptions)`
- in Compose, `AndroidFragment<ReactNativeFragment>` with the `ReactNativeFragmentArgNames`
constants (`ARG_MODULE_NAME`, `ARG_LAUNCH_OPTIONS`)
- see [runtime-api.md](./runtime-api.md#kotlin) for the full signatures
5. Verify host app resolves dependency and RN module renders.
- Capture agent-assisted device evidence, using `agent-device` when possible.
## Stop Conditions
Mark complete only if:
- Gradle sync/build succeeds with published coordinate
- runtime initializes before UI creation
- RN module renders expected screen
## If Failed
- Re-check coordinate and repository order
- Re-package and re-publish if artifact is stale
- Re-check module name registration in JS
## Canonical Docs
- [Android Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/android.md)
- [Guidelines](https://oss.callstack.com/react-native-brownfield/docs/guides/guidelines.md)
- [Troubleshooting](https://oss.callstack.com/react-native-brownfield/docs/guides/troubleshooting.md)
## Common Pitfalls
- Missing `mavenLocal()`
- Dependency coordinate mismatch
- Creating RN UI before host manager initialization
## Related Skills
- [runtime-api.md](./runtime-api.md) - Host <-> RN API surface
- [bare-android-aar-generation.md](./bare-android-aar-generation.md) - Bare Android artifact generation
- [bare-quick-start.md](./bare-quick-start.md) - Bare setup prerequisites
bare-ios-native-integration.md 3.6 KB
---
title: Bare iOS Native Integration
impact: HIGH
tags: react-native, brownfield, bare, ios, swiftui, appdelegate
---
# Skill: Bare iOS Native Integration
Integrate bare RN XCFramework artifacts into native iOS host app and verify startup/runtime behavior.
## Quick Command
```swift
ReactNativeBrownfield.shared.bundle = ReactNativeBundle
ReactNativeBrownfield.shared.startReactNative { print("React Native bundle loaded") }
```
`ReactNativeBundle` comes from the packaged framework's interface file, not from `ReactBrownfield`.
For the full property and overload list, see [runtime-api.md](./runtime-api.md#swift).
## When to Use
- Consuming generated bare RN XCFrameworks in host iOS app
- Wiring runtime initialization for UIKit or SwiftUI entrypoints
## Prerequisites
- [bare-ios-xcframework-generation.md](./bare-ios-xcframework-generation.md) completed
- Artifacts available in package output (`ios/.brownfield/package/build`)
- Host app builds in Xcode
## Agent-Assisted Verification
Use `agent-device` after the host build succeeds. Read the `agent-device` skill or CLI help when available before exact commands. If it is missing and verification needs it, install it through the environment's approved/trusted path or ask the user to install or enable it. Then open the host app, navigate to the RN surface, capture snapshots/screenshots, and collect logs for Debug and Release behavior.
## Step-by-Step Instructions
```text
Progress checklist:
- [ ] Link generated frameworks
- [ ] Initialize RN startup
- [ ] Render registered module
- [ ] Verify Debug and Release behavior
```
1. Link every XCFramework from the package output into the host app — see
[cli-and-config.md](./cli-and-config.md#outputs) for what is emitted.
2. In app startup:
```swift
import <framework_target_name>
ReactNativeBrownfield.shared.bundle = ReactNativeBundle
ReactNativeBrownfield.shared.startReactNative(
launchOptions: launchOptions,
preloadBundle: true
) {
print("React Native bundle loaded")
}
```
Forward the app delegate callbacks the host implements, including `open url` and
`continue userActivity` when deep links must reach the RN surface.
3. Render RN UI with JS-registered module name:
- UIKit: `ReactNativeViewController(moduleName: "<registered_module_name>")`
- SwiftUI: `ReactNativeView(moduleName: "<registered_module_name>")`
4. Validate:
- Debug with Metro (`npx react-native start`)
- Release without Metro
- Agent-assisted device evidence, using `agent-device` when possible
## Stop Conditions
Mark complete only if:
- host app builds in Debug and Release
- RN module renders in both configurations
## If Failed
- Re-check startup order: set bundle -> start runtime -> create RN view/controller
- Re-check `moduleName` matches `AppRegistry.registerComponent`
- Re-link all required frameworks if Release cannot load JS
## Canonical Docs
- [iOS Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/ios.md)
- [Swift API](https://oss.callstack.com/react-native-brownfield/docs/api-reference/react-native-brownfield/swift.md)
- [Troubleshooting](https://oss.callstack.com/react-native-brownfield/docs/guides/troubleshooting.md)
## Common Pitfalls
- Missing `ReactNativeBrownfield.shared.bundle = ReactNativeBundle`
- Wrong module name compared to JS registration
- Linking only app XCFramework without brownfield/hermes frameworks
## Related Skills
- [runtime-api.md](./runtime-api.md) - Host <-> RN API surface
- [bare-ios-xcframework-generation.md](./bare-ios-xcframework-generation.md) - Bare iOS artifact generation
- [bare-quick-start.md](./bare-quick-start.md) - Bare setup prerequisites
bare-ios-xcframework-generation.md 3.4 KB
---
title: Bare iOS XCFramework Generation
impact: CRITICAL
tags: react-native, brownfield, bare, ios, xcframework, xcode
---
# Skill: Bare iOS XCFramework Generation
Package a bare React Native app into XCFramework artifacts for native iOS host consumption.
## Quick Command
```bash
npx brownfield package:ios --scheme <framework_target_name> --configuration Release --destination simulator
```
Record `scheme`/`configuration` in `brownfield.config.*` instead of repeating them — see
[cli-and-config.md](./cli-and-config.md) for the full option set. Omitting `--destination` also
builds the device slice, which a simulator QA loop never loads.
## When to Use
- Building iOS artifacts from a bare RN app
- Rebuilding XCFramework after RN/native dependency updates
## Prerequisites
- [bare-quick-start.md](./bare-quick-start.md) completed
- Framework target exists in `ios/*.xcworkspace`
- Podfile includes framework target with `inherit! :complete`
- If running `pod install` directly, static linking is configured as recommended in iOS integration docs
- Framework target build settings:
- Build Libraries for Distribution = `YES`
- User Script Sandboxing = `NO`
- Skip Install = `NO`
- Enable Module Verifier = `NO`
## Step-by-Step Instructions
```text
Progress checklist:
- [ ] Framework target + Podfile ready
- [ ] Bundle script present on framework target
- [ ] Public interface file exports ReactBrownfield
- [ ] package:ios succeeds
- [ ] Artifacts validated
```
1. Create or verify framework target in Xcode workspace.
- If target folders are folder references, convert them to groups (per iOS integration docs).
2. Ensure Podfile has nested framework target and run `pod install`.
3. Ensure framework target includes `Bundle React Native code and images` run script with expected input files (`$(SRCROOT)/.xcode.env.local`, `$(SRCROOT)/.xcode.env`).
4. Add framework interface file:
```swift
@_exported import ReactBrownfield
public let ReactNativeBundle = Bundle(for: InternalClassForBundle.self)
class InternalClassForBundle {}
```
5. Package framework:
- `npx brownfield package:ios --scheme <framework_target_name> --configuration Release --destination simulator`
6. Validate the package output directory, `ios/.brownfield/package/build` — see
[cli-and-config.md](./cli-and-config.md#outputs) for what lands there.
## Stop Conditions
Proceed only if:
- package command exits with code `0`
- all required frameworks are present in package output
## If Failed
- Re-run pods and retry package command
- Re-check framework target build settings and run script phase
- Do not proceed to host integration until artifacts are complete
## Canonical Docs
- [iOS Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/ios.md)
- [Brownfield CLI](https://oss.callstack.com/react-native-brownfield/docs/cli/brownfield.md)
- [Troubleshooting](https://oss.callstack.com/react-native-brownfield/docs/guides/troubleshooting.md)
## Common Pitfalls
- Packaging app target instead of framework target
- Missing bundle run script on framework target
- Incomplete framework set linked into host app
## Related Skills
- [cli-and-config.md](./cli-and-config.md) - Full CLI option set, config file, artifact layout
- [bare-quick-start.md](./bare-quick-start.md) - Bare setup prerequisites
- [bare-ios-native-integration.md](./bare-ios-native-integration.md) - Bare iOS host integration
bare-quick-start.md 2.0 KB
---
title: Bare React Native Quick Start
impact: CRITICAL
tags: react-native, brownfield, bare, setup, cocoapods, gradle
---
# Skill: Bare React Native Quick Start
Prepare a bare React Native project for brownfield packaging and host integration.
## Quick Command
```bash
npm install @callstack/react-native-brownfield
cd ios && pod install && cd ..
```
## When to Use
- User explicitly chooses bare React Native path
- Project directly manages native iOS/Android folders
## Prerequisites
- Bare RN app with working `ios/` and `android/`
- CocoaPods and Gradle working
## Step-by-Step Instructions
```text
Progress checklist:
- [ ] Install package
- [ ] Install pods
- [ ] Create brownfield config
- [ ] Continue to bare platform packaging
```
1. Install package in RN app root.
2. Run `pod install` for iOS.
3. Create `brownfield.config.js` or `brownfield.config.json` with the iOS scheme and the Android
module name and variant, so packaging commands stay short — see
[cli-and-config.md](./cli-and-config.md).
4. Continue with one platform packaging file:
- [bare-ios-xcframework-generation.md](./bare-ios-xcframework-generation.md)
- [bare-android-aar-generation.md](./bare-android-aar-generation.md)
## Canonical Docs
- [Quick Start](https://oss.callstack.com/react-native-brownfield/docs/getting-started/quick-start.md)
- [iOS Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/ios.md)
- [Android Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/android.md)
## Common Pitfalls
- Starting packaging before `pod install`
- Mixing Expo-only startup APIs into bare flow
## Related Skills
- [cli-and-config.md](./cli-and-config.md) - CLI commands, config file, artifacts
- [quick-start.md](./quick-start.md) - Shared path-selection gate
- [bare-ios-xcframework-generation.md](./bare-ios-xcframework-generation.md) - Bare iOS artifact generation
- [bare-android-aar-generation.md](./bare-android-aar-generation.md) - Bare Android artifact generation
cli-and-config.md 9.4 KB
---
title: Brownfield CLI and Configuration
impact: CRITICAL
tags: react-native, brownfield, cli, configuration, packaging
---
# Skill: Brownfield CLI and Configuration
The command and configuration contract for the `brownfield` CLI. Read this before composing any
packaging or publish command, and before adding flags to a `package.json` script.
## Discover options before trusting this file
Flags move between versions. Run `npx brownfield <command> --help` for the command you are about to
use and reconcile it with the tables below. Where they disagree, **the help output wins** — update
this file rather than working around it.
## Commands
| Command | Purpose |
| ------- | ------- |
| `package:ios` | Build the iOS XCFramework artifacts |
| `package:android` | Build the Android AAR |
| `publish:android` | Publish the AAR to Maven local |
| `codegen` | Generate native Brownie store bindings |
| `navigation:codegen` | Generate Brownfield Navigation native bindings |
`--verbose` is a global option available on every command.
The binary ships inside `@callstack/brownfield-cli`, which is a dependency of
`@callstack/react-native-brownfield` — installing the brownfield package is enough to get `npx brownfield`.
### `package:ios`
| Flag | Notes |
| ---- | ----- |
| `--scheme <name>` | Framework target to build. Required whenever the packaged framework cannot be resolved unambiguously |
| `--configuration <name>` | Case sensitive. Defaults to `Debug` when neither the flag nor the config sets it |
| `--target <name>` | Xcode target |
| `--destination <strings...>` | Slices to build: `simulator`, `device`, or any `xcodebuild -destination` value. Omitted, **both** are built |
| `--use-prebuilt-rn-core [bool]` | Use React Native Apple prebuilt binaries for the packaging build. Omitted, the default is version-aware; the flag without a value means `true` |
| `--use-prebuilt-expo [bool]` | Use prebuilt Expo support XCFrameworks instead of compiling Expo modules. Omitted, the default is version-aware; the flag without a value means `true` |
| `--add-spm-package` | Generate a local Swift package manifest next to the packaged XCFrameworks |
| `--build-folder <path>` | Intermediate build directory. Defaults to `.brownfield/build` |
| `--extra-params <string>` | Extra `xcodebuild` parameters |
| `--export-extra-params <string>` | Extra export parameters |
| `--export-options-plist <path>` | Defaults to `ExportOptions.plist` |
| `--no-install-pods` | Skip the CocoaPods install step |
| `--no-new-arch` | Build without the New Architecture |
| `--verbose` | Verbose logging |
Both boolean-valued flags accept `true`/`1`/`false`/`0`; anything else fails with
`Invalid value for <flag>: expected true or false`.
`--archive` and `--local` are inherited from the underlying build tooling, so they are accepted but
unsupported. **Do not plan a migration step around them** — archive the host app in Xcode against
the packaged frameworks instead.
### `package:android` / `publish:android`
| Flag | Commands | Notes |
| ---- | -------- | ----- |
| `--module-name <name>` | both | The AAR module. Spelling follows the project: a Gradle path such as `:BrownfieldLib` for a bare app whose module is declared in `settings.gradle`, or a plain name such as `brownfieldlib` for the Expo plugin default |
| `--variant <name>` | `package:android` | Build variant from build type plus product flavor, e.g. `release` or `devRelease` |
| `--use-local-maven` | both | Resolve the Brownfield Gradle plugin from the local Maven repository. **Not documented upstream** — confirmed in the CLI source |
| `--verbose` | both | Verbose logging |
### `codegen` and `navigation:codegen`
| Command | Flags |
| ------- | ----- |
| `codegen` | `-p, --platform <swift\|kotlin>`. Omitted, both are generated |
| `navigation:codegen` | `[specPath]` positional (defaults to `brownfield.navigation.ts`), `--dry-run` |
You rarely run these by hand — see [Side effects](#side-effects-codegen-runs-automatically).
## Configuration file
Put stable per-project settings in a config file and keep only per-run flags on the command line.
A project driven this way runs a bare `npx brownfield package:ios`.
Exactly one source is allowed. Two or more raises
`Project has multiple Brownfield configuration files`:
1. `brownfield.config.js` (project root)
2. `brownfield.config.json` (project root)
3. the `brownfield` key in `package.json`
### Shape
```json
{
"$schema": "https://oss.callstack.com/react-native-brownfield/schema.json",
"verbose": true,
"ios": {
"scheme": "BrownfieldLib",
"configuration": "Release",
"expo": {}
},
"android": {
"moduleName": "brownfieldlib",
"variant": "release",
"expo": { "useLocalMaven": true }
},
"brownie": {
"kotlin": "./android/brownfieldlib/src/main/java/<package_path>/Generated/",
"kotlinPackageName": "<kotlin_package_name>"
}
}
```
- `ios` accepts the `package:ios` options; `android` accepts the `package:android` and
`publish:android` options. Use the camelCase form of each flag (`--use-prebuilt-expo` ->
`usePrebuiltExpo`, `--add-spm-package` -> `addSpmPackage`, `--module-name` -> `moduleName`).
- `ios.expo` and `android.expo` are **Expo config plugin** options for the prebuild scaffolding
(framework name, bundle identifier, deployment target, Android package name, SDK versions,
Maven coordinates, Proguard rules, missing dimension strategies). They are a different layer from
the packaging flags above — consult the Expo integration docs for the current key list.
- `brownie` configures Brownie codegen output. A top-level `brownie` key in `package.json` is the
legacy location and warns; prefer the nested key shown here.
- The config is validated against the published JSON schema. Validation problems are warnings,
not errors — a typo'd key is silently ignored, so read the warnings.
### Precedence
CLI options override config values for the same key, and the CLI logs a warning naming each
overridden key and both values. Treat those warnings as a signal that a command line and a config
file disagree about the project, and fix one of them.
### Working shapes to copy
Each of the three sources has a working example in the `react-native-brownfield` repo's apps —
see [Reference apps](./runtime-api.md#reference-apps).
## Outputs
iOS artifacts land in `<ios_source_dir>/.brownfield/package/build`, and the intermediate build
directory is `<ios_source_dir>/.brownfield/build`. For a bare app that is `ios/.brownfield/...`;
for an Expo app the same paths apply under the prebuilt `ios/` directory.
What appears there:
- `<framework_target_name>.xcframework`
- `ReactBrownfield.xcframework` (binary stripped — it is interface-only, to avoid duplicate symbols)
- `hermesvm.xcframework` (named `hermes.xcframework` on older React Native; hosts that expect one
name may need the other renamed)
- `Brownie.xcframework`, when the project uses Brownie
- `BrownfieldNavigation.xcframework`, when the project uses Brownfield Navigation
- React Native and Expo support XCFrameworks emitted alongside, when prebuilts are in use
With `--add-spm-package`, the XCFrameworks are moved into a `spm-artifacts/` subdirectory and
`Package.swift` is written next to them. See
[expo-ios-integration.md](./expo-ios-integration.md#spm-host---add-spm-package) for wiring the
package into the host project — the CLI does not do that part.
Android artifacts are published to Maven local by `publish:android` under the group, artifact and
version configured in the library module's publishing block.
## Side effects: codegen runs automatically
`package:ios`, `package:android` and `publish:android` each run Brownie codegen and Brownfield
Navigation codegen first, when the project uses those packages. Consequences:
- A change to a Brownie store definition or a navigation spec is picked up by the next package run.
You do not need a separate codegen step before packaging.
- Generated native sources are refreshed under `node_modules` and, for Kotlin, at the configured
`brownie.kotlin` output path. Do not hand-edit generated files; change the spec and re-package.
- A codegen failure fails the package command before any build work happens — read the first error,
not the last.
For the store and navigation contracts themselves, use the dedicated `brownie` and
`brownfield-navigation` skills if they are installed. They are distributed separately from this
skill, so invoke them by name rather than by path.
## Canonical Docs
- [Brownfield CLI](https://oss.callstack.com/react-native-brownfield/docs/cli/brownfield.md)
- [Configuration](https://oss.callstack.com/react-native-brownfield/docs/api-reference/configuration.md)
- [Expo Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/expo.md)
## Common Pitfalls
- Repeating the same flags on every command instead of writing them once to `brownfield.config.*`
- Two config sources present at once (the CLI refuses to run)
- Assuming a flag exists because it appears in an older reference, instead of running `--help`
- Planning around `--archive` / `--local` on `package:ios`
- Treating the config schema warning as harmless when a key was simply misspelled
- Looking for artifacts under `.brownfield/package` instead of `.brownfield/package/build`
## Related Skills
- [runtime-api.md](./runtime-api.md) - Host <-> RN API surface
- [expo-ios-integration.md](./expo-ios-integration.md) - Expo iOS packaging and host wiring
- [bare-ios-xcframework-generation.md](./bare-ios-xcframework-generation.md) - Bare iOS packaging
expo-android-integration.md 3.6 KB
---
title: Expo Android Integration
impact: HIGH
tags: react-native, brownfield, expo, android, aar, reactnativehostmanager
---
# Skill: Expo Android Integration
Package and publish Expo Android AAR, then initialize host runtime and mount RN UI.
## Quick Command
```bash
npx brownfield package:android --module-name <android_module_name> --variant release
npx brownfield publish:android --module-name <android_module_name>
```
Record `moduleName`/`variant` and the `android.expo` plugin options in `brownfield.config.*`
instead of repeating them — see [cli-and-config.md](./cli-and-config.md) for the full option set.
## When to Use
- User requests Expo Android brownfield integration
- Host app must consume Expo-backed RN AAR
## Prerequisites
- [expo-quick-start.md](./expo-quick-start.md) completed
- Android host app builds and syncs
- Android module name resolved (`brownfieldlib` by default unless overridden in Expo plugin options)
## Agent-Assisted Verification
Use `agent-device` after the host build succeeds. Read the `agent-device` skill or CLI help when available before exact commands. If it is missing and verification needs it, install it through the environment's approved/trusted path or ask the user to install or enable it. Then open the host app, navigate to the Expo-backed RN surface, capture snapshots/screenshots, and collect logs for runtime behavior.
## Step-by-Step Instructions
```text
Progress checklist:
- [ ] Package AAR
- [ ] Publish to Maven local
- [ ] Initialize host runtime
- [ ] Render RN module
```
1. Build AAR:
- `npx brownfield package:android --module-name <android_module_name> --variant release`
2. Publish to Maven local:
- `npx brownfield publish:android --module-name <android_module_name>`
3. Initialize runtime in `Activity` or `Application`:
```kotlin
ReactNativeHostManager.initialize(application) {
Toast.makeText(this, "React Native has been loaded", Toast.LENGTH_LONG).show()
}
```
4. Forward configuration changes:
```kotlin
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
ReactNativeHostManager.onConfigurationChanged(application, newConfig)
}
```
5. Render RN UI with JS-registered module name:
- `ReactNativeFragment.createReactNativeFragment("<registered_module_name>", initialProps)`
- or `ReactNativeBrownfield.shared.createView(activity, "<registered_module_name>", reactDelegate, launchOptions)`
- in Compose, `AndroidFragment<ReactNativeFragment>` with the `ReactNativeFragmentArgNames`
constants
- see [runtime-api.md](./runtime-api.md#kotlin) for the full signatures
## Stop Conditions
Mark complete only if:
- package and publish commands both exit with code `0`
- host app resolves published dependency and renders module
- device evidence is captured with `agent-device` when possible
## Canonical Docs
- [Expo Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/expo.md)
- [Android Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/android.md)
- [Brownfield CLI](https://oss.callstack.com/react-native-brownfield/docs/cli/brownfield.md)
## Common Pitfalls
- Using `ComponentActivity` with Expo (use `AppCompatActivity`)
- Missing `ReactNativeHostManager.initialize(...)` before UI creation
- Module name mismatch with `AppRegistry.registerComponent`
## Related Skills
- [cli-and-config.md](./cli-and-config.md) - Full CLI option set, config file, artifact layout
- [runtime-api.md](./runtime-api.md) - Host <-> RN API surface
- [expo-quick-start.md](./expo-quick-start.md) - Expo setup and plugin wiring
- [expo-ios-integration.md](./expo-ios-integration.md) - Expo iOS equivalent
expo-create-app.md 1.6 KB
---
title: Expo Create App for Brownfield
impact: CRITICAL
tags: react-native, brownfield, expo, create-app, setup
---
# Skill: Expo Create App for Brownfield
Create a new Expo app as the source project for Expo brownfield packaging and host integration.
## Quick Command
```bash
npx create-expo-app@latest my-expo-brownfield --yes
```
## When to Use
- User wants to add React Native to native apps via Expo path
- No existing Expo/RN project is available for brownfield packaging
## Prerequisites
- Node.js and `npx` available
- New project directory name selected
## Step-by-Step Instructions
```text
Progress checklist:
- [ ] Create Expo app
- [ ] Install brownfield package
- [ ] Continue on Expo-only path
```
1. Create a new Expo app in a standalone directory (not inside existing iOS/Android host repo).
2. `cd my-expo-brownfield`
3. Install brownfield package: `npm install @callstack/react-native-brownfield`
4. Continue to [expo-quick-start.md](./expo-quick-start.md).
## Stop Conditions
Proceed only if:
- create command exits with code `0`
- `app.json` exists at project root
## Canonical Docs
- [Expo Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/expo.md)
- [Quick Start](https://oss.callstack.com/react-native-brownfield/docs/getting-started/quick-start.md)
## Common Pitfalls
- Creating Expo app inside host native app project
- Jumping to iOS/Android integration before Expo plugin setup
## Related Skills
- [quick-start.md](./quick-start.md) - Path-selection gate
- [expo-quick-start.md](./expo-quick-start.md) - Expo plugin and packaging setup
expo-ios-integration.md 11.3 KB
---
title: Expo iOS Integration
impact: HIGH
tags: react-native, brownfield, expo, ios, xcframework, spm, swiftui, appdelegate
---
# Skill: Expo iOS Integration
Package Expo app as XCFramework artifacts, link them into host iOS app, and initialize Expo-compatible RN runtime.
## Quick Command
```bash
npx brownfield package:ios --scheme <framework_target_name> --configuration Release --destination simulator
```
Add `--add-spm-package` for a Swift Package Manager host, and `--use-prebuilt-expo false` when Expo prebuilts are unavailable (see [Packaging flags](#packaging-flags)).
## When to Use
- User requests Expo iOS brownfield integration
- Host app must render Expo-backed React Native UI
## Prerequisites
- [expo-quick-start.md](./expo-quick-start.md) completed
- iOS host app builds successfully
- Framework scheme name resolved (`BrownfieldLib` by default unless overridden in Expo plugin options)
- Shell locale is UTF-8 (`LANG`/`LC_ALL`); CocoaPods raises `Encoding::CompatibilityError` otherwise. Recent CLI versions default this, older ones need `LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8`.
## Host App Inventory (before packaging)
Inspect the host once; it decides which steps below apply:
1. **Dependency manager**: CocoaPods (`Podfile`), Swift Package Manager (`Package.swift` or `XCLocalSwiftPackageReference` in the `.xcodeproj`), or Tuist (`Project.swift`).
2. **Xcode 16+ synchronized groups**: search `project.pbxproj` for `PBXFileSystemSynchronizedRootGroup`. If the host target uses one, new Swift files dropped in that folder are picked up without pbxproj edits; otherwise new files must be added to the target explicitly.
3. **Startup entry point**: SwiftUI `@main App` or a UIKit `AppDelegate`/`SceneDelegate`.
## Packaging flags
The full option set, the config file, and the artifact layout live in
[cli-and-config.md](./cli-and-config.md). Two flags need Expo-specific judgment.
### `--destination simulator`
Omitting the flag builds both slices, and the device slice is dead weight when QA runs on a simulator. Pass `--destination simulator` unless:
- QA for this task runs on a **physical device**
- the task produces an **archive / TestFlight build** (archived from the host app in Xcode against the packaged frameworks)
- the host app goes to someone who will run it on hardware
### `--use-prebuilt-expo` and `usePrecompiledModules`
Prebuilt Expo XCFrameworks only exist when `expo-build-properties` does **not** set `ios.usePrecompiledModules: false` in `app.json` / `app.config.*`. If that property is `false`:
- the CLI now reports it up front and treats the version-inferred default as off;
- an explicit `--use-prebuilt-expo true` fails, because the artifacts can never be produced.
Choose one exit, respecting the user's preference: pass `--use-prebuilt-expo false` (Expo modules are built from source), or enable `usePrecompiledModules`, run `pod install`, and package again.
Older CLI versions do not check this: they build for several minutes, print `Success`, and then fail because the prebuilt XCFrameworks are missing. If that happens, re-run with `--use-prebuilt-expo false`.
## Agent-Assisted Verification
Use `agent-device` after the host build succeeds. Read the `agent-device` skill before exact commands. If it is missing and verification needs it, install it through the environment's approved/trusted path or ask the user to install or enable it. Then open the host app, navigate to the Expo-backed RN surface, capture snapshots/screenshots, and collect logs for Debug and Release behavior.
## Step-by-Step Instructions
```text
Progress checklist:
- [ ] Inventory host app
- [ ] Package XCFrameworks
- [ ] Link frameworks in host app (CocoaPods/Xcode or local SPM package)
- [ ] Configure startup
- [ ] Render RN module
- [ ] Verify on simulator
```
1. Package iOS artifacts:
- `npx brownfield package:ios --scheme <framework_target_name> --configuration Release --destination simulator`
2. Link every XCFramework from the package output directory (`ios/.brownfield/package/build`) into the host app project — see [cli-and-config.md](./cli-and-config.md#outputs) for what lands there.
3. Initialize runtime in app entrypoint. Set `bundle` and `ensureExpoModulesProvider()` **before** `startReactNative`; `startReactNative` must be the last operation:
```swift
@main
struct IosApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
init() {
ReactNativeBrownfield.shared.bundle = ReactNativeBundle
ReactNativeBrownfield.shared.ensureExpoModulesProvider()
// `preloadBundle` pays the bundle evaluation cost at startup so the first
// RN screen appears faster. See runtime-api.md for the other overloads.
ReactNativeBrownfield.shared.startReactNative(
launchOptions: nil,
preloadBundle: true
) {
print("React Native has been loaded")
}
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
```
4. Forward the app delegate callbacks the host implements — `didFinishLaunchingWithOptions` at minimum, plus `open url` / `continue userActivity` for deep links (see [runtime-api.md](./runtime-api.md#swift)):
```swift
class AppDelegate: NSObject, UIApplicationDelegate {
var window: UIWindow?
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
return ReactNativeBrownfield.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
```
5. Render RN UI using the module registered in JS (`AppRegistry.registerComponent`):
- `ReactNativeView(moduleName: "<registered_module_name>")`
- or `ReactNativeBrownfield.shared.view(moduleName: "<registered_module_name>", initialProps: nil)`
## Debug frameworks and `preferEmbeddedBundleInDebug`
A framework packaged in **Debug** looks for Metro on `localhost:8081`. With no Metro running, the app launches, shows nothing where the RN surface should be, and logs no obvious crash. To run a Debug framework without Metro, opt in to the embedded bundle before `startReactNative` (default `false`):
```swift
ReactNativeBrownfield.shared.bundle = ReactNativeBundle
ReactNativeBrownfield.shared.preferEmbeddedBundleInDebug = true
ReactNativeBrownfield.shared.startReactNative()
```
This only helps when no Metro is reachable at all — see the pitfall in [runtime-api.md](./runtime-api.md#common-pitfalls).
## SPM host (`--add-spm-package`)
The flag moves the XCFrameworks into `spm-artifacts/` and writes `Package.swift` plus a README next to them. The manifest lists the XCFrameworks that were actually emitted; do not hand-edit it to add prebuilt Expo frameworks that were not produced.
**Wiring the package into the host `.xcodeproj` is a separate step; the CLI does not write `XCLocalSwiftPackageReference`.** With Xcode open: File > Add Package Dependencies... > Add Local... and select the package output directory, then add the package products to the host target.
### Linking the local package headlessly
Agent environments have no Xcode GUI, so script the "Add Local..." step with the `xcodeproj` Ruby gem against the host project — the same three objects Xcode would write:
```ruby
# gem install xcodeproj
require 'xcodeproj'
project = Xcodeproj::Project.open('<host>.xcodeproj')
target = project.targets.find { |t| t.name == '<host_target>' }
pkg_path = '<relative/path/to/package/output/dir>' # e.g. ../rn-app/ios/.brownfield/package/build
# 1. XCLocalSwiftPackageReference — the local package itself
ref = project.new(Xcodeproj::Project::Object::XCLocalSwiftPackageReference)
ref.relative_path = pkg_path
project.root_object.package_references << ref
# 2. XCSwiftPackageProductDependency — the product to consume
dep = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
dep.product_name = '<product_name>' # e.g. BrownfieldLib
target.package_product_dependencies << dep
# 3. PBXBuildFile with productRef — link it into Frameworks
build_file = project.new(Xcodeproj::Project::Object::PBXBuildFile)
build_file.product_ref = dep
target.frameworks_build_phase.files << build_file
project.save
```
Then verify the file is still well formed: `plutil -lint <host>.xcodeproj/project.pbxproj`.
Notes:
- `relative_path` is resolved from the `.xcodeproj` directory. Point it at the directory containing `Package.swift`, not at the manifest.
- If the gem is unavailable and cannot be installed, stop and report that as the blocker. Do not hand-edit `project.pbxproj` as text, and do not fall back to CocoaPods in an SPM-only host without the user agreeing to it.
## Verification recipe
1. List simulators: `xcrun simctl list devices available`, and pick a UDID.
2. Build with the UDID, not the device name: `xcodebuild -scheme <host_scheme> -destination id=<UDID> ... build`.
3. Install and launch, then verify with `agent-device`.
4. Simulator screenshot pixels are not device points: on modern iPhones the scale is 3x. Convert before tapping by coordinate.
**Do not decide pass/fail from `xcodebuild -quiet`.** It suppresses `** BUILD SUCCEEDED **` while still printing `error: the following command failed with exit code 0 but produced no further output` around whole-module-optimization batches on a successful build. Pipe through `xcbeautify` when installed, and judge the outcome on exit status first, then `** BUILD SUCCEEDED **` / `** BUILD FAILED **`, then a fresh `.app`.
## Stop Conditions
Mark complete only if:
- package command exits with code `0` and its final completion line appears (the dependency prints `Success` before post-build steps finish)
- host app builds in Debug; also in Release for any feature slice, visual-parity work, or release candidate, where the module must be verified rendering in Release too. Debug alone is enough for a first infra/plumbing pass, but say so in the handoff.
- selected module renders successfully
- device evidence is captured with `agent-device` when possible
## Canonical Docs
- [Expo Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/expo.md)
- [iOS Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/ios.md)
- [Swift API](https://oss.callstack.com/react-native-brownfield/docs/api-reference/react-native-brownfield/swift.md)
## Common Pitfalls
- Calling `ensureExpoModulesProvider()` after `startReactNative`, or missing it entirely
- Omitting `shared.bundle = ReactNativeBundle` (blank screen)
- Debug framework without `preferEmbeddedBundleInDebug` and without Metro (blank screen)
- Forcing `--use-prebuilt-expo true` while `ios.usePrecompiledModules` is `false`
- Assuming `--add-spm-package` links the package into the host project
- Packaging without `--destination simulator` and paying for a device slice nothing loads
- Trusting `xcodebuild -quiet` to report success
- Not forwarding `didFinishLaunchingWithOptions`
- Using wrong module name instead of JS-registered component name
- Running under a non-UTF-8 locale (CocoaPods encoding error)
## Related Skills
- [cli-and-config.md](./cli-and-config.md) - Full CLI option set, config file, artifact layout
- [runtime-api.md](./runtime-api.md) - Host <-> RN API surface
- [expo-quick-start.md](./expo-quick-start.md) - Expo setup and plugin wiring
- [expo-android-integration.md](./expo-android-integration.md) - Expo Android equivalent
expo-quick-start.md 3.8 KB
---
title: Expo Brownfield Quick Start
impact: CRITICAL
tags: react-native, brownfield, expo, app.json, plugin, setup
---
# Skill: Expo Brownfield Quick Start
Configure Expo project for brownfield packaging before iOS/Android host integration.
## Quick Command
```bash
npm install @callstack/react-native-brownfield
```
## When to Use
- Expo managed or prebuild project needs brownfield packaging
- Continuing after [expo-create-app.md](./expo-create-app.md)
## Prerequisites
- Expo project with `app.json`
- Expo path selected in router
## Step-by-Step Instructions
```text
Progress checklist:
- [ ] Install package
- [ ] Configure plugin
- [ ] Create brownfield config
- [ ] Continue to platform integration
```
1. Install package in the Expo project.
2. Add plugin to `app.json`:
```json
{
"plugins": ["@callstack/react-native-brownfield"]
}
```
3. Create the brownfield configuration — the iOS scheme, the Android module name and variant, and
any `ios.expo` / `android.expo` plugin options — so packaging commands stay short. See
[cli-and-config.md](./cli-and-config.md); exactly one config source is allowed.
4. Optionally add package scripts for packaging/publish commands used by your team.
5. If the app uses `expo-router`, set up the brownfield entry point (see [Expo Router entry point](#expo-router-entry-point)).
6. Continue to exactly one platform file:
- [expo-ios-integration.md](./expo-ios-integration.md)
- [expo-android-integration.md](./expo-android-integration.md)
## Expo Router entry point
Apply this only when the app uses `expo-router` and the native host must mount a named module. Do not change `package.json.main` for bare React Native apps, Expo apps without `expo-router`, or projects that already have a working brownfield entry point.
`expo-router/entry` registers only Expo's default `main` component, so the native host cannot look up its own module name. If `package.json` has `"main": "expo-router/entry"`, change it to `"index.tsx"` and create `index.tsx` at the project root:
```tsx
import { registerRootComponent } from 'expo';
import { AppRegistry } from 'react-native';
import { App as ExpoRouterApp } from 'expo-router/build/qualified-entry';
export const BROWNFIELD_MODULE_NAME = 'MyBrownfieldModule';
// Keeps Expo's default "main" registration (expo start, expo run:ios, fast refresh).
registerRootComponent(ExpoRouterApp);
// Registers the same root under the name the native host mounts:
// ReactNativeBrownfield.shared.view(moduleName: "MyBrownfieldModule")
AppRegistry.registerComponent(BROWNFIELD_MODULE_NAME, () => ExpoRouterApp);
```
Notes:
- Import `App` from `expo-router/build/qualified-entry`. It resolves `expo-router/_ctx` against the auto-detected router root (for example `src/app`), so do not hand-roll `require.context('./app')` with a hardcoded path.
- Adapt `BROWNFIELD_MODULE_NAME` to the module name the host uses; it must equal the string passed to `ReactNativeView(moduleName:)` / `view(moduleName:)`.
- To expose additional feature modules, add more `AppRegistry.registerComponent('<Name>', () => <Component>)` lines. Import local files without a `.tsx` extension.
## Canonical Docs
- [Expo Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/expo.md)
- [Brownfield CLI](https://oss.callstack.com/react-native-brownfield/docs/cli/brownfield.md)
## Common Pitfalls
- Missing plugin entry in `app.json`
- `package.json.main` still `expo-router/entry`, so the native module name is never registered
- Mixing Expo flow with bare packaging files
## Related Skills
- [cli-and-config.md](./cli-and-config.md) - CLI commands, config file, artifacts
- [quick-start.md](./quick-start.md) - Path-selection gate
- [expo-ios-integration.md](./expo-ios-integration.md) - Expo iOS integration
- [expo-android-integration.md](./expo-android-integration.md) - Expo Android integration
quick-start.md 2.2 KB
---
title: Brownfield Quick Start
impact: CRITICAL
tags: react-native, brownfield, setup, path-selection, expo, bare
---
# Skill: Brownfield Quick Start
Run shared setup, select one path (Expo or bare), and route immediately to path-specific instructions.
## Quick Command
```bash
npm install @callstack/react-native-brownfield
```
## When to Use
- Starting brownfield setup and deciding between Expo and bare RN
- Preparing project prerequisites before platform-specific packaging
## Prerequisites
- React Native project root identified
- Node.js and package manager available
## Step-by-Step Instructions
```text
Progress checklist:
- [ ] Install package
- [ ] Select Expo or bare path
- [ ] Continue only on selected path
```
1. Install package in the React Native app root.
2. Classify request/project intent:
- Expo signals: `expo`, `prebuild`, Expo plugin workflow
- Bare signals: direct RN CLI workflow, explicit XCFramework/AAR-only path
3. Route to exactly one path:
- Expo path: [expo-create-app.md](./expo-create-app.md) (if no RN app yet) -> [expo-quick-start.md](./expo-quick-start.md)
- Bare path: [bare-quick-start.md](./bare-quick-start.md)
4. If unclear, ask one disambiguation question and stop.
## Stop Conditions
Proceed only if:
- package install exits with code `0`
- exactly one path is selected
## If Failed
- If install fails, retry with the active package manager and lockfile sync
- If path intent is ambiguous, stop and ask one Expo vs bare question
## Canonical Docs
- [Quick Start](https://oss.callstack.com/react-native-brownfield/docs/getting-started/quick-start.md)
- [Expo Integration](https://oss.callstack.com/react-native-brownfield/docs/getting-started/expo.md)
## Common Pitfalls
- Mixing Expo and bare steps in one flow
- Starting platform integration before path selection
## Related Skills
- [cli-and-config.md](./cli-and-config.md) - CLI commands, config file, artifacts
- [runtime-api.md](./runtime-api.md) - Host <-> RN API surface
- [expo-create-app.md](./expo-create-app.md) - Create new Expo app for brownfield
- [expo-quick-start.md](./expo-quick-start.md) - Expo setup and plugin wiring
- [bare-quick-start.md](./bare-quick-start.md) - Bare RN baseline setup
runtime-api.md 10.1 KB
---
title: Brownfield Runtime API
impact: HIGH
tags: react-native, brownfield, api, swift, kotlin, javascript, host-boundary
---
# Skill: Brownfield Runtime API
The host <-> React Native boundary surface: what JavaScript can call, what the native host sets up,
and which mechanism to pick for a given task. Read this before hand-rolling a bridge.
## Choosing a boundary mechanism
| Need | Use |
| ---- | --- |
| Leave the RN surface and return to the native stack | `popToNative()` |
| Hand the back gesture / hardware back button to native | `setNativeBackGestureAndButtonEnabled()` |
| Call a **typed, named** native screen or action from RN (navigate to a native screen, ask the host for a confirmation) | Brownfield Navigation — `brownfield-navigation` skill (if installed) |
| Share **state** between host and RN (session, user, theme) with a single source of truth | Brownie — `brownie` skill (if installed) |
| One-off, untyped signal in either direction | `postMessage()` / `onMessage()` |
Prefer the typed options. `postMessage` is the escape hatch: it is a JSON string with no contract,
so it does not survive refactoring the way a generated navigation or store binding does.
## JavaScript
`@callstack/react-native-brownfield` default-exports exactly four methods.
```ts
import ReactNativeBrownfield from '@callstack/react-native-brownfield';
import type { MessageEvent } from '@callstack/react-native-brownfield';
ReactNativeBrownfield.popToNative(true); // `animated` is iOS-only
ReactNativeBrownfield.setNativeBackGestureAndButtonEnabled(true);
ReactNativeBrownfield.postMessage({ text: 'hello', id: 2 }); // must be JSON-serializable
const subscription = ReactNativeBrownfield.onMessage((event: MessageEvent) => {
console.log(event.data);
});
subscription.remove();
```
Notes:
- `popToNative(animated)` ignores `animated` on Android.
- `postMessage` calls `JSON.stringify` without catching — serialization errors are the caller's.
- `onMessage` parses the incoming payload as JSON and falls back to the raw string on failure.
- `BrownfieldConfig` is re-exported as a type, for annotating `brownfield.config.js`.
## Swift
Module name is `ReactBrownfield`. Entry point is `ReactNativeBrownfield.shared`.
Properties set **before** `startReactNative`:
| Property | Notes |
| -------- | ----- |
| `bundle: Bundle` | Where the JS bundle is looked up. Defaults to `.main`, which is wrong for a brownfield host — see below |
| `preferEmbeddedBundleInDebug: Bool` | Default `false`. Set `true` to run a Debug framework without Metro |
| `entryFile: String` | Defaults to `index`, or the Expo virtual metro entry in an Expo project |
| `bundlePath: String` | Defaults to `main.jsbundle` |
| `bundleURLOverride: (() -> URL?)?` | Full control over bundle resolution |
Lifecycle and rendering:
```swift
// three overloads
ReactNativeBrownfield.shared.startReactNative()
ReactNativeBrownfield.shared.startReactNative(onBundleLoaded: { })
ReactNativeBrownfield.shared.startReactNative(
launchOptions: launchOptions,
preloadBundle: true, // loads and evaluates the bundle now; first RN screen appears faster
onBundleLoaded: { }
)
ReactNativeBrownfield.shared.stopReactNative()
// rendering
ReactNativeView(moduleName: "<registered_module_name>") // SwiftUI, iOS 15+
ReactNativeViewController(moduleName: "<registered_module_name>",
initialProperties: nil) // UIKit
ReactNativeBrownfield.shared.view(moduleName: "<registered_module_name>",
initialProps: nil) // raw UIView
// messaging
ReactNativeBrownfield.shared.postMessage("<json string>")
let token = ReactNativeBrownfield.shared.onMessage { message in }
```
There is **no** `startReactNative(onBundleLoaded:launchOptions:)` overload. Pass `launchOptions`
through the three-argument form, or forward the app delegate callbacks below.
App delegate forwarding — forward every callback the host actually implements:
```swift
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool
func application(_ application: UIApplication,
willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool
```
Deep links into the RN surface need the `open url` and `continue userActivity` forwards, not just
`didFinishLaunchingWithOptions`.
### Two symbols that are not library exports
`ReactNativeBundle` and `ensureExpoModulesProvider()` are **generated into the packaged framework**
(`FrameworkInterface.swift`) — by the Expo config plugin for Expo projects, or written by hand for a
bare framework target. They come from `import <framework_target_name>`, not from `ReactBrownfield`.
Omitting `shared.bundle = ReactNativeBundle` leaves the host without a bundle URL and the RN surface
renders blank with no crash.
## Kotlin
Package `com.callstack.reactnativebrownfield`. Hosts should call a project-owned
`ReactNativeHostManager` facade rather than these APIs directly.
```kotlin
// recommended: the factory lambda runs after native libs are loaded
ReactNativeBrownfield.initialize(application, onJSBundleLoaded) { reactHost }
// also supported
ReactNativeBrownfield.initialize(application, packages: List<ReactPackage>, onJSBundleLoaded)
ReactNativeBrownfield.initialize(application, options: HashMap<String, Any>, onJSBundleLoaded)
// option keys: packages, mainModuleName, bundleAssetPath, bundleFilePath, useDeveloperSupport
// DEPRECATED: the reactHost argument is evaluated before native libs load, which breaks
// ExpoReactHostFactory. Use the factory-lambda overload instead.
ReactNativeBrownfield.initialize(application, reactHost, onJSBundleLoaded)
```
Rendering and messaging:
```kotlin
ReactNativeFragment.createReactNativeFragment("<registered_module_name>", initialProps)
ReactNativeBrownfield.shared.createView(
activity, // FragmentActivity?
"<registered_module_name>",
reactDelegate = null,
launchOptions = null,
) // -> FrameLayout
// five-argument overload adds `lifecycleOwner` for a container shorter-lived than the activity
ReactNativeBrownfield.shared.postMessage("<json string>")
ReactNativeBrownfield.shared.addMessageListener(listener)
ReactNativeBrownfield.shared.removeMessageListener(listener)
```
In Compose, mount the fragment with `AndroidFragment<ReactNativeFragment>` and pass arguments using
the `ReactNativeFragmentArgNames` constants (`ARG_MODULE_NAME`, `ARG_LAUNCH_OPTIONS`) rather than
raw strings.
`OnJSBundleLoaded` and `OnMessageListener` are `fun interface`s, so a lambda works for both.
## Reference apps
The `react-native-brownfield` repo carries working producers and hosts. Read the one matching your
path before writing integration code — they are more current than any snippet.
| App | Role |
| --- | ---- |
| `apps/RNApp` | Bare RN producer: framework target, `Podfile` nesting, Gradle library module, `ReactNativeHostManager`; JS config with a `BrownfieldConfig` type annotation |
| `apps/ExpoApp57` | Expo producer driven entirely by `brownfield.config.json`; package scripts are bare commands |
| `apps/ExpoApp58` | Expo producer with config under the `package.json` `brownfield` key; packaging flags stay on the scripts |
| `apps/AppleApp` | iOS host: linked XCFrameworks, SwiftUI `@main` startup, app delegate forwarding, navigation delegate |
| `apps/AndroidApp` | Android host: `mavenLocal()`, per-producer flavors, Compose `AndroidFragment<ReactNativeFragment>` |
## Canonical Docs
- [Swift API](https://oss.callstack.com/react-native-brownfield/docs/api-reference/react-native-brownfield/swift.md)
- [Kotlin API](https://oss.callstack.com/react-native-brownfield/docs/api-reference/react-native-brownfield/kotlin.md)
- [JavaScript API](https://oss.callstack.com/react-native-brownfield/docs/api-reference/react-native-brownfield/javascript.md)
## Common Pitfalls
- Expecting `ReactNativeBundle` or `ensureExpoModulesProvider()` from `import ReactBrownfield`
- Calling a `startReactNative` overload that does not exist (`onBundleLoaded:launchOptions:`)
- Using the deprecated `initialize(application, reactHost, ...)` in an Expo host
- Forwarding only `didFinishLaunchingWithOptions` and then wondering why deep links do not reach RN
- Reaching for `postMessage` where a typed navigation call or a Brownie store belongs
- Building a second navigation stack in RN instead of calling `popToNative` back into the host's
- **`preferEmbeddedBundleInDebug` does not protect against a reachable-but-wrong Metro server.** It only
applies when no Metro URL resolves at all. Any Metro holding the configured port (default `8081`) — even
one started for an unrelated project — is fetched by a Debug-configured framework, which then crashes with
an `AppRegistry` "has not been registered" error. Check `lsof -i :8081` before suspecting the integration;
to force the embedded bundle, package the framework as `Release`. The `#if DEBUG` here comes from
`ios.configuration` in the brownfield config, not the host app's Xcode configuration.
- **A brownfield view controller pushed by mutating `UINavigationController.viewControllers` can silently
fail to attach to the window** when that navigation controller is hosted inside a SwiftUI
`UIViewControllerRepresentable`: the RN view mounts with live content but `view.window == nil`. Prefer
`present(rnViewController, animated: true)` (with `modalPresentationStyle = .fullScreen` to replace rather
than stack) over `setViewControllers(...)`, and check `view.window != nil` before blaming the bundle.
## Related Skills
- [cli-and-config.md](./cli-and-config.md) - CLI commands, config file, artifacts
- `brownie` skill (if installed) - Shared host <-> RN state
- `brownfield-navigation` skill (if installed) - Typed RN -> native navigation
License (MIT)
View full license text
MIT License Copyright (c) 2026 Callstack Incubator Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.