【问题标题】:Error: null is not an object (evaluating 'C.State') <unknown> index.android.bundle错误:null 不是对象(评估“C.State”)<unknown> index.android.bundle
【发布时间】:2019-01-30 06:49:46
【问题描述】:

我是 React-Native 的新手。我正在将我现有的 Android 本机应用程序与反应本机应用程序集成。 运行应用程序后的 react native 部分显示此错误:

null 不是对象(评估“C.State”) 未知 index.android.bundle

这是错误的屏幕截图: Screenshot of error message

我知道每次使用 react-navigationreact-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


【解决方案1】:

我有一个类似的问题,我做了什么来解决它,它是阅读 React Navigation 文档,在这个页面中是我的解决方案:

https://reactnavigation.org/docs/en/getting-started.html

之后,如果您的 settings.gradle 文件中出现如下错误:

FAILURE:构建失败并出现异常。

  • 地点:

设置文件 'C:\PATH\TO\YOUR\PROYECT\android\settings.gradle' 行:3...

在您的 settings.gradle 文件中,将这些字符“\”更改为您看到以下内容的行中的“/”:'..\node_modules\react-native-gesture-handler\android'

就是这样,希望我能帮上忙……

【讨论】:

  • settings.gradle 文件中的所有斜杠(“/”)都已经正确,没有反斜杠(“\”)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-05
  • 2021-10-20
  • 2016-06-08
  • 1970-01-01
  • 1970-01-01
  • 2023-03-04
相关资源
最近更新 更多