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

末鹿安然 提交于 2019-12-02 21:01:56

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 :

  • the import package : import com.airbnb.android.react.maps.MapsPackage
  • the call to the constructor of the module : new MapsPackage() in function getPackages

Go to file "MainApplication.java" (under .\android\app\src\main\java\com\projectName)

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

HM Hamza Zubair

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 :

  • cd android
  • ./gradlew clean
  @Override    
  public boolean canOverrideExistingModule() {        
    return true;    
  }   

Add these code to your native module constructor would be fine

You can try check in file MainApplication.java in directory : android\app\src\main\java is have any duplicate package AirMapModule exist or not, and delete 1 if have.

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.

check your MainApplication.java, in particular protected List<ReactPackage> getPackages(); the AirMapModule is probably twice in the list

if installed library react-navigation you can run via android studio. else remove library react-navigation and just yarn it's will work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!