yamill/react-native-orientation

App can not compile

jcabrerazuniga opened this issue · 2 comments

After installing and running my app I am getting:

Native module Orientation tried to override OrientationModule. Check the getPackages() method in MainApplication.java, it might be that module is being created twice. If this was your intention, set canOverrideExistingModule=true. This error may also be present if the package is present only once in getPackages() but is also automatically added later during build time by autolinking. Try removing the existing entry and rebuild

I am using

"dependencies": {
"react": "16.13.1",
"react-native": "0.63.4",
"react-native-orientation": "^3.1.3",
"react-native-sensors": "^7.2.0",
"rxjs": "^6.6.6"
},

Issue : Android Platform

I had followed the installation guide form React Native Orientation, and had the error:

Native module Orientation tried to override OrientationModule.

Dependencies

"react-native-orientation": "^3.1.3", "react-native": "^0.64.0",

Solution

Two changes to consider on point three of the guide: 3. Register module in MainApplication.java

  1. Most likely the version of react native 0.64.0 already has import com.github.yamill.orientation.OrientationPackage; so skip this. If you already have imported that might be the reason for duplicate OrientationModule.

  2. In the getPackages() do not add the mentioned line new OrientationPackage() or packages.add(new OrientationPackage()); .

Code Slution

import com.github.yamill.orientation.OrientationPackage;
// import com.github.yamill.orientation.OrientationPackage;  // <--- Should not  Add, comment out or delete

public class MainApplication extends Application implements ReactApplication {
  ......

 @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());

          // packages.add(new OrientationPackage()); //  <------- Should not add, comment out or delete

          return packages;
        }

  ......

}

Gradle

Make sure to clear your gradle caches .\gradlew cleanBuildCache

Additional NOTE: I unlinked or skipped react-native link react-native-orientation

Hi Team,
I am also facing this issue from long time.

Check the getPackages() method in MainApplication.java, it might be that module is being created twice. If this was your intention, set canOverrideExistingModule=true. This error may also be present if the package is present only once in getPackages() but is also automatically added later during build time by autolinking. Try removing the existing entry and rebuild.
Can anyone have fixed this issue