getPackages() method in MainApplication.java, the module might be created twice

Viewed 6809
3 Answers

In step 2 of setting up react-native-razorpay, I was adding these 2 lines in MainApplication.java:

import com.razorpay.rn.RazorpayPackage;

and

packages.add(new RazorpayPackage());

I got rid of this error by removing these 2 lines. The package is automatically added later on during build time by autolinking. Removing these 2 lines solved my issue.

I had a similar error but with a different package. Looks as though the packages are added much later I have no idea when and how though. React Native "^0.64.0"

Native module Orientation tried to override OrientationModule. Check the getPackages() method in MainApplication.java, it might be that module is being created twice.

Solution

In MainApplication.java:

  1. I had to remove or comment out duplicate import of OrientationPackage

// import com.github.yamill.orientation.OrientationPackage; <----- Commented out or removed

  1. And not add the package to List<ReactPackage>

// packages.add(new OrientationPackage()); // <----- Commented out or removed

We need to check if any duplicate imports are there or not, or if any duplicate lines are there inside getPackages() method. If the issue is still not resolved then we need to add the following lines of code inside the module class(which extends ReactContextBaseJavaModule) inside node_modules folder...

Refer to this link for a similar problem I found on stackoverflow-

How to set canOverrideExistingModule=true in React Native for Android Apps?

@Override    
  public boolean canOverrideExistingModule() {        
    return true;    
  }   

Related