1

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.

Piyush Govil
  • 358
  • 3
  • 13
  • 1
    It's really not possible to tell anything from a bundler error like that. Try working backwards, adding your native module one bit at a time – Kai Jan 30 '19 at 07:01
  • additionally, a good place to start would be to double check that you're initializing and importing the native module properly – Kai Jan 30 '19 at 07:03
  • Thanks Kai, I'll try to run it again freshly from scratch. – Piyush Govil Jan 30 '19 at 08:53
  • I don't know what was the mistake before, but now after I did the process again from scratch, it's working now. Thanks. – Piyush Govil Jan 31 '19 at 05:47
  • @Kai the error came again when I used react-navigation and react-native-gesture-handler – Piyush Govil Feb 06 '19 at 12:12

1 Answers1

0

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...