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

Clash Royale CLAN TAG#URR8PPP
How to set canOverrideExistingModule=true in React Native for Android Apps?
I built an android app using React Native, it got built successfully but when I run the app in my Android Virtual Device it shows up a full red screen with the following error:

I have not done native app development ever before neither do I have any knowledge of Java so I have no idea what this error means and how to fix this.
5 Answers
5
The name of the package associated to this error is not AirMapModule but MapsPackage from com.airbnb.android.react.maps.
AirMapModule
MapsPackage
com.airbnb.android.react.maps
In your MainApplication.java in directory : android/app/src/main/java/../../ remove any duplicate entry of :
MainApplication.java
android/app/src/main/java/../../
import com.airbnb.android.react.maps.MapsPackage
new MapsPackage()
getPackages
This error rise when you are trying to import same package twice in MainApplication.java file
– Digvijay Machale
Feb 12 at 5:26
this works but everytime i link a library it repeat itself
– Sir Koswara
Mar 6 at 2:37
just remove the duplicate imports from MainApplication.java
– John
May 4 at 19:48
Specially signed in to upvote these answers
– Akshay Seth
Aug 3 at 12:15
Go to file "MainApplication.java" (under .androidappsrcmainjavacomprojectName)
Make sure that under getPackages() function you don't have duplicate lines (in my case I had "new MapsPackage()" twice).
Fix duplicate imports as well.
Good luck
@Override
public boolean canOverrideExistingModule()
return true;
Add these code to your native module constructor would be fine
Does not work for me
– fungusanthrax
Sep 26 '17 at 20:50
You can try check in file MainApplication.java in directory : androidappsrcmainjava is have any duplicate package AirMapModule exist or not, and delete 1 if have.
MainApplication.java
androidappsrcmainjava
There is neither a package nor even a variable by the name AirMapModule in the file MailApplication.java :(
– UtkarshPramodGupta
Jan 25 '17 at 9:16
what version of react-native you use ?
– Nguyên Hoàng
Jan 25 '17 at 9:22
react-native-cli: 2.0.1 react-native: 0.36.0
– UtkarshPramodGupta
Jan 25 '17 at 9:43
Did you try to check file
MainActivity.java in the same directory too ?– Nguyên Hoàng
Jan 25 '17 at 10:25
MainActivity.java
Yeah, i just did. Even that doesn't have anything related to AirMapModule. :(
– UtkarshPramodGupta
Jan 25 '17 at 10:58
Go to the MainAplication file..
Remove duplicate package and remove duplicate package in getPackages() method
@Override
protected List<ReactPackage> getPackages()
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new VectorIconsPackage()
);
Then after try this command in your terminal :
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
The first bullet is mentioned everywhere online, but this was the first mention of the second place to look for duplicates. Thank you.
– David Sinclair
Jun 16 '17 at 21:37