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 err
The name of the package associated to this error is not AirMapModule
but MapsPackage
from com.airbnb.android.react.maps
.
In your MainApplication.java
in directory : android/app/src/main/java/../../
remove any duplicate entry of :
import com.airbnb.android.react.maps.MapsPackage
new MapsPackage()
in function getPackages
check your MainApplication.java
, in particular protected List<ReactPackage> getPackages()
; the AirMapModule
is probably twice in the list
If the version of RN you're using is >= 0.60 then there is the possibility that auto-linking and your manual linking are doing the same thing twice. You have two options:
1- You can revert code changes in getPackages
method
2- You can disable auto linking in react-native-config.js
file.
Go to your module (coz of which you are getting this error message) Open the module.. add this code to it...
@Override
public boolean canOverrideExistingModule() {
return true;
}
if installed library react-navigation you can run via android studio. else remove library react-navigation and just yarn it's will work.
The above solutions are all correct, but let me explain a little bit,some of above solutions suggest to override the following method.
@Override
public boolean canOverrideExistingModule() {
return true;
}
But question is where to override? first of all, you can't override inside MainActivity.java or MainApplication.java file.
You should override it in the class inside some node_modules project folder and that class will be extending from ReactContextBaseJavaModule class.
In my case, it was not getting repeated in imports/adding duplicate packages but it was mainly because of auto linking at the and that was making it to repeat.
I am using react-native-contacts npm package to interact so what I did is that went inside
node_modules\react-native-contacts\android\src\main\java\comrt2zz\reactnativecontacts\
ContactsManager.java
and this ContactsManager was extending from the ReactContextBaseJavaModule and I override there and got the problem resolved.
So as general there could be a lot of classes that will be extending from ReactContextBaseJavaModule under different projects inside node_modules, but you need to go for specific a project that will be creating duplication problem and there you should override it.