Android: generated ReactNativeHostManager loads React Native twice and crashes (Feature flags cannot be overridden more than once)
維護者通常 3 天內回覆
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 72/100
研究方向
從 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 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
callstack/react-native-brownfield 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 85/100
callstack/react-native-brownfield#502 ·
維護者通常 3 天內回覆
-
難度 4/5 3-5 天 新手友好度 55/100
callstack/react-native-brownfield#468 ·
維護者通常 3 天內回覆
-
難度 4/5 3-5 天 新手友好度 48/100
callstack/react-native-brownfield#420 ·
維護者通常 3 天內回覆
-
難度 5/5 一週以上 新手友好度 38/100
callstack/react-native-brownfield#406 ·
維護者通常 3 天內回覆
-
Common network layer可能重新可做 @dratwas 於 2552 天前認領,目前沒有進行中的 PR。 未關閉
callstack/react-native-brownfield#23 · 已指派 1 人 ·
維護者通常 3 天內回覆
查看 callstack/react-native-brownfield 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 85/100
MoonshotAI/kimi-code#4398 ·
維護者通常 1 天內回覆
-
pending triage
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
package-lock.json : les binaires natifs macOS et Linux de unrs-resolver ont disparu depuis #1823未關閉bug dependencies
難度 2/5 1-3 小時 新手友好度 70/100
AxaFrance/design-system#2064 ·
維護者通常 3 天內回覆
-
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 85/100