Skip to content

Android: generated ReactNativeHostManager loads React Native twice and crashes (Feature flags cannot be overridden more than once) #492

Closed

Description

@gronxb

The ReactNativeHostManager.kt that npm create @callstack/react-native-brownfield generates for a React Native CLI project crashes when the native app starts React Native:

java.lang.RuntimeException: Feature flags cannot be overridden more than once
  at com.facebook.react.internal.featureflags.ReactNativeFeatureFlags.override(ReactNativeFeatureFlags.kt:558)
  at com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load(DefaultNewArchitectureEntryPoint.kt:101)
  at com.callstack.reactnativebrownfield.ReactNativeBrownfield$Companion.loadNativeLibsInternal(ReactNativeBrownfield.kt:49)
  at com.callstack.reactnativebrownfield.ReactNativeBrownfield$Companion.initialize(ReactNativeBrownfield.kt:66)
  at com.rnapp.ReactNativeHostManager.initialize(ReactNativeHostManager.kt:28)

Cause: the template (ReactNativeHostManager.vanilla.kt) calls loadReactNative(application) and then ReactNativeBrownfield.initialize(application, reactHost, ...). Both run DefaultNewArchitectureEntryPoint.load(), which sets React Native's feature flags, so the second call throws. The nativeLibsLoaded guard in ReactNativeBrownfield.kt can't see the earlier loadReactNative call.

Repro: https://github.com/gronxb/react-native-brownfield-492-repro. It has the scaffold output and a minimal native Android app that starts React Native from a button. The README has the steps, and the comment below has videos of the crash and the fix.

Fix: remove loadReactNative(application) and pass the React host as a factory, as the Expo template (ReactNativeHostManager.post55.kt) already does:

ReactNativeBrownfield.initialize(application, onJSBundleLoaded) {
    getDefaultReactHost(
        context = application,
        packageList = PackageList(application).packages,
        jsMainModulePath = "index",
        jsBundleAssetPath = "index.android.bundle",
        jsBundleFilePath = null,
        useDevSupport = BuildConfig.DEBUG,
        jsRuntimeFactory = null
    )
}

Removing only loadReactNative is not enough. The template builds the host (val reactHost by lazy { getDefaultReactHost(...) }) as an argument to the deprecated initialize(application, reactHost, ...) overload, so it is built before initialize loads the native libraries, and the app then fails with SoLoader.init() not yet called. loadReactNative also turns on edge-to-edge when IS_EDGE_TO_EDGE_ENABLED is set, so a template fix should keep that part.

Tested with: @callstack/create-react-native-brownfield 5.3.0, @callstack/react-native-brownfield 5.3.0, React Native 0.85.2, Android emulator (API 37).

Edited: the first version of this issue suggested removing only loadReactNative, which isn't enough, as explained above.

Activity

  1. gronxb commented on Oct 14, 2026

    @gronxb
    ContributorAuthor

    I put together a repro for this: https://github.com/gronxb/react-native-brownfield-492-repro

    Branch Result
    main (template as generated) crashes with Feature flags cannot be overridden more than once
    issue-fix (only loadReactNative removed, the fix this issue first suggested) crashes with SoLoader.init() not yet called
    working-fix (factory overload) starts and renders the React Native screen

    The host app opens on a native screen and starts React Native from its "Open React Native" button.

    As generated (main): the app crashes when the native screen starts React Native.

    crash.mp4

    With the factory overload (working-fix): React Native renders below the native header.

    fixed.mp4

    The README has the steps, versions, and both stack traces. I tested with create-react-native-brownfield 5.3.0 and React Native 0.85.2 on an Android emulator (API 37).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions