I'm trying to integrate Razorpay with my react-native application using there official documentation from- https://razorpay.com/docs/payment-gateway/react-native-integration/standard/android/ but I'm getting this exception while running the application. No duplicate imports are there inside the MainApplication.java.

- 340
- 1
- 3
- 10
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.

- 2,214
- 6
- 33
- 47

- 592
- 6
- 10
-
2This is the exact solution with proper reasoning. The Razorpay docs seems out of date regarding these steps. – Ankush Chauhan Nov 26 '20 at 16:46
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
:
- I had to remove or comment out duplicate import of OrientationPackage
// import com.github.yamill.orientation.OrientationPackage; <----- Commented out or removed
- And not add the package to
List<ReactPackage>
// packages.add(new OrientationPackage()); // <----- Commented out or removed

- 89
- 1
- 4
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;
}

- 340
- 1
- 3
- 10
-
2Hey @Sandip, can you please point out the exact files where you added this snippet? I am facing the exact same issue. – sudonitin Jul 19 '20 at 11:45
-
1@globefire Inside android node_modules package check for the java module class which is extending ReactContextBaseJavaModule there you have to add those lines. Sorry for such a late reply – Sandip Biswas Jul 24 '20 at 21:01
-
Never mind @Sandip, there's some technical issue from razorpay, they asked me to downgrade the version – sudonitin Jul 24 '20 at 21:04