我是 React-Native 的新手。我正在将我现有的 Android 本机应用程序与 react 本机应用程序集成在一起。运行应用程序后的本机部分显示此错误:
null 不是对象(评估“C.State”)未知index.android.bundle
这是错误的 屏幕截图:错误消息的屏幕截图
我知道每次使用react-navigation和react-native-gesture-handler 时都会出现此错误消息。
这是 package.json 文件的代码:
{
"name": "Demo",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.6.3",
"react-native": "^0.58.3",
"react-native-gesture-handler": "^1.0.15",
"react-navigation": "^3.1.4"
},
"devDependencies": {
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "24.0.0",
"jest": "24.0.0",
"metro-react-native-babel-preset": "0.51.1",
"react-test-renderer": "16.6.3"
},
"jest": {
"preset": "react-native"
}
}
这是呈现 react-native module的本机活动:
public class MyReactActivity extends Activity implements DefaultHardwareBackBtnHandler {
private ReactRootView mReactRootView;
private ReactInstanceManager mReactInstanceManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModulePath("index.android")
.addPackage(new MainReactPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
Bundle initialProps = new Bundle();
String str = MainActivity.getMovieID();
initialProps.putString("movie_id", str);
mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", initialProps);
setContentView(mReactRootView);
}
观察上面代码中编写的 index.android.bundle 。
同样在运行应用程序之前,我运行此命令来解决无法从资产 index.android.bundle 加载脚本的问题
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src /主要/资源
这里也观察到 index.android.bundle 正在做一些事情
找不到与此错误相关的任何内容。任何帮助将不胜感激。谢谢。