Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

已關閉 適合新手
#492 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 3 天內回覆

已經有一個關聯 PR 被合併了。

  • #497 來自 @github-actions —— 已合併
  • #500 來自 @hurali97 —— 已合併

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
72/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
android, kotlin, react-native
領域
mobile

研究方向

從 expo-config-plugin 範本資料夾中產生的範本 ReactNativeHostManager.vanilla.kt 開始,並與 ReactNativeBrownfield.kt 比較,後者的 initialize 會呼叫 loadNativeLibs(SoLoader.init 與 DefaultNewArchitectureEntryPoint.load)。透過產生專案並啟動應用程式來重現問題。當範本不再呼叫 loadReactNative(application),且應用程式啟動時沒有功能開關錯誤,即完成。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
TypeScript
星號
552
分支
56
平均合併
3 天 8 小時
30 天內合併 PR
23

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

callstack/react-native-brownfield 的其他 Issue

查看 callstack/react-native-brownfield 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。