Error: null is not an object (evaluating 'C.State') <unknown> index.android.bundle

↘锁芯ラ 提交于 2020-01-03 02:59:10

问题


I am new to React-Native. I was integrating my existing Android native app with react native app. The react native part after running app is showing this error:

null is not an object (evaluating 'C.State') unknown index.android.bundle

Here is the screenshot of the error: Screenshot of error message

I know that this error message comes every time I use react-navigation and react-native-gesture-handler.

Here is the code for package.json file:

{
  "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"
  }
}

Here is the native activity that renders the 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);
}

Observe the index.android.bundle written in above code.

Also before running the app I run this command to resolve the 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/app/src/main/res

Here too observe that something is being done at index.android.bundle

Can't find anything related to this error. Any help will be appreciated. Thanks.


回答1:


I had a similar problem, what I did to fix it, it was to read the React Navigation documentation, in this page it is my solution:

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

After that, if you have an error in your settings.gradle file that says something like this:

FAILURE: Build failed with an exception.

  • Where:

Settings file 'C:\PATH\TO\YOUR\PROYECT\android\settings.gradle' line: 3...

In your settings.gradle file, change these characters "\" for this one "/" in the line where you see this: '..\node_modules\react-native-gesture-handler\android'

And that's it, hope I was able to help...



来源:https://stackoverflow.com/questions/54434786/error-null-is-not-an-object-evaluating-c-state-unknown-index-android-bund

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!