Android: generated ReactNativeHostManager loads React Native twice and crashes (Feature flags cannot be overridden more than once)
メンテナーはふだん 4 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 72/100
調査の方向性
expo-config-plugin のテンプレートフォルダにある、生成されたテンプレート ReactNativeHostManager.vanilla.kt から始め、initialize が loadNativeLibs(SoLoader.init と DefaultNewArchitectureEntryPoint.load を呼び出す)を呼んでいる ReactNativeBrownfield.kt と比較してください。プロジェクトを生成してアプリを起動し、問題を再現します。テンプレートが 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
- フォーク
- 53
- 平均マージ
- 4日 13時間
- マージ済み PR(30日)
- 15
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
callstack/react-native-brownfield のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
callstack/react-native-brownfield#468 ·
メンテナーはふだん 4 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
callstack/react-native-brownfield#420 ·
メンテナーはふだん 4 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
callstack/react-native-brownfield#406 ·
メンテナーはふだん 4 日以内に返信
-
Common network layer再び着手できるかも @dratwas が 2542 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
callstack/react-native-brownfield#23 · 担当者 1 名 ·
メンテナーはふだん 4 日以内に返信
-
Add support for bottom tabs再び着手できるかも @krizzu が 2542 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
callstack/react-native-brownfield#22 · 担当者 1 名 ·
メンテナーはふだん 4 日以内に返信
callstack/react-native-brownfield の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
xdjs/MusicNerdWeb#1532 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
sebastian-software/ardo#352 ·
メンテナーはふだん 1 日以内に返信
-
@react95/core good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 3 日以内に返信
-
@shikijs/stream: `ShikiStreamTokenizer.clone()` shares its `tokensStable` array with the original対応中かも @xyrolle が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 6 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信