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

前端 未结 12 914
我寻月下人不归
我寻月下人不归 2020-12-23 18:53

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

相关标签:
12条回答
  • 2020-12-23 19:23

    Solution

    Goto android/app/src/main/java/YOURPACKAGE/MainApplication.java

    Find method getPackages();

    Remove this packages.add(new MapsPackage());

    Chill Pill! :)

    0 讨论(0)
  • 2020-12-23 19:25

    Open the MainApplication.java file by this address: android/app/src/main/java/com/projectName/MainApplication.java and add the following code to MainApplication.java file:

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

    And everything became correct.

    0 讨论(0)
  • 2020-12-23 19:27

    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.

    0 讨论(0)
  • 2020-12-23 19:32

    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.

    0 讨论(0)
  • 2020-12-23 19:37

    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
    0 讨论(0)
  • 2020-12-23 19:37

    Add only the modules which are not autolinked at here,

            @Override
            protected List<ReactPackage> getPackages() {
              @SuppressWarnings("UnnecessaryLocalVariable")
              List<ReactPackage> packages = new PackageList(this).getPackages();
              // Packages that cannot be autolinked yet can be added manually here, for 
              // example: packages.add(new MyReactNativePackage());         
              return packages;
            }
    
    

    If the module is autolinked and added the module here, you will get this error.

    0 讨论(0)
提交回复
热议问题