【发布时间】:2019-01-30 06:49:46
【问题描述】:
我是 React-Native 的新手。我正在将我现有的 Android 本机应用程序与反应本机应用程序集成。 运行应用程序后的 react native 部分显示此错误:
null 不是对象(评估“C.State”) 未知 index.android.bundle
这是错误的屏幕截图: Screenshot of error message
我知道每次使用 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 模块的原生活动:
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。
另外,在运行应用程序之前,我会运行此命令来解析 Unable to load script from assets 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/应用程序/src/main/res
这里也观察到 index.android.bundle 正在做一些事情
找不到与此错误相关的任何内容。任何帮助将不胜感激。谢谢。
【问题讨论】:
-
这样的捆绑程序错误真的无法分辨。尝试向后工作,一次添加一个本地模块
-
此外,一个好的开始是仔细检查您是否正确初始化和导入本机模块
-
感谢 Kai,我会尝试从头开始重新运行它。
-
我不知道之前的错误是什么,但是现在我从头开始重新执行该过程后,它现在可以工作了。谢谢。
-
@Kai 当我使用 react-navigation 和 react-native-gesture-handler 时错误又来了
标签: android reactjs react-native react-navigation hybrid-mobile-app