React native 本机模块方向尝试重写方向模块-未找到重复项

React native 本机模块方向尝试重写方向模块-未找到重复项,react-native,react-native-android,android-orientation,React Native,React Native Android,Android Orientation,当我尝试安装react native orientation/orientation locker时,我(在Android上)遇到了这个错误。根据错误信息和在线浏览解决方案,我发现更改MainApplication.java中的包会有所帮助(因为在那里会创建此库包的多个实例;特别是getPackages()方法)。但就我而言,情况并非如此。在我的项目中找不到同一实例的多个条目 我没有以任何方式编辑mainApplication.java文件。我还附上了mainApplication.java和m

当我尝试安装react native orientation/orientation locker时,我(在Android上)遇到了这个错误。根据错误信息和在线浏览解决方案,我发现更改MainApplication.java中的包会有所帮助(因为在那里会创建此库包的多个实例;特别是getPackages()方法)。但就我而言,情况并非如此。在我的项目中找不到同一实例的多个条目

我没有以任何方式编辑mainApplication.java文件。我还附上了mainApplication.java和mainActivity.java文件,以获得更好的概述

有人能帮我吗? 我的react原生版本是0.63,我也没有手动链接库。(我确实试过一次,也犯了同样的错误。)


你找到解决办法了吗?我也一样error@AndresUrdaneta是的,我确实找到了解决办法。在我的软件包列表中,我也安装了react native VLC。实际上已经在使用本机模块定向。移除vlc库解决了这个问题。您可以使用Android studio来检测特定库正在使用哪些本机模块
MainApplication.java
package com.companyABC;

import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.sbugert.rnadmob.RNAdMobPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
// import from RNBranch
import io.branch.rnbranch.RNBranchModule;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost =
      new ReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
          return BuildConfig.DEBUG;
        }

        @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 CompanyABCPackage());
//           packages.add(new RNAdMobPackage());
          return packages;
        }

        @Override
        protected String getJSMainModuleName() {
          return "index";
        }
      };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
    RNBranchModule.getAutoInstance(this);
    initializeFlipper(this); // Remove this line if you don't want Flipper enabled
  }

  /**
   * Loads Flipper in React Native templates.
   *
   * @param context
   */
  private static void initializeFlipper(Context context) {
    if (BuildConfig.DEBUG) {
      try {
        /*
         We use reflection here to pick up the class that initializes Flipper,
        since Flipper library is not available in release mode
        */
        Class<?> aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper");
        aClass.getMethod("initializeFlipper", Context.class).invoke(null, context);
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }
  }
}
MainActivity.java
package com.companyabc;

import com.facebook.react.ReactActivity;
import org.devio.rn.splashscreen.SplashScreen;

import android.os.Build;
import android.os.Bundle;
import io.branch.rnbranch.*;
import android.content.Intent;
import android.widget.Toast;
import android.content.res.Configuration;

public class MainActivity extends ReactActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this);
    super.onCreate(savedInstanceState);
  }

@Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    Intent intent = new Intent("onConfigurationChanged");
    intent.putExtra("newConfig", newConfig);
    this.sendBroadcast(intent);
  }
  /**
   * Returns the name of the main component registered from JavaScript. This is used to schedule
   * rendering of the component.
   */
  @Override
  protected String getMainComponentName() {
    return "CompanyABC";
  }

  // Override onStart, onNewIntent:
  @Override
  protected void onStart() {
    super.onStart();
    RNBranchModule.initSession(getIntent().getData(), this);
  }

  @Override
  public void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    RNBranchModule.onNewIntent(intent);
  }
}
Package.json
{
  "name": "companyABC",
  "version": "1.0.2",
  "private": true,
  "scripts": {
    "android": "react-native run-android --no-jetifier",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "postversion": "react-native-version",
    "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
  },
  "dependencies": {
    "@apollo/client": "^3.2.0",
    "@react-native-community/async-storage": "^1.9.0",
    "@react-native-community/cli-platform-android": "^2.9.0",
    "@react-native-community/clipboard": "^1.2.3",
    "@react-native-community/datetimepicker": "^2.6.2",
    "@react-native-community/masked-view": "^0.1.7",
    "@react-native-firebase/admob": "^7.6.12",
    "@react-native-firebase/app": "^9.0.0",
    "@react-native-firebase/messaging": "^8.0.1",
    "@react-navigation/bottom-tabs": "^5.2.4",
    "@react-navigation/native": "^5.1.3",
    "@react-navigation/stack": "^5.2.8",
    "@sentry/react-native": "^1.9.0",
    "@twotalltotems/react-native-otp-input": "^1.3.11",
    "@types/isomorphic-fetch": "^0.0.35",
    "@types/react-native-keep-awake": "^2.0.2",
    "@types/react-native-snap-carousel": "^3.8.1",
    "@types/react-native-video": "^5.0.1",
    "@types/react-redux": "^7.1.7",
    "@types/underscore": "^1.9.4",
    "@types/uuid": "^7.0.3",
    "add": "^2.0.6",
    "bluebird": "^3.7.2",
    "date-fns": "^1.29.0",
    "graphql": "^15.3.0",
    "i18next": "^19.4.5",
    "isomorphic-fetch": "^2.2.1",
    "moment": "^2.29.1",
    "native-base": "^2.13.12",
    "react": "16.9.0",
    "react-compound-timer": "^1.2.0",
    "react-flv-player": "^1.0.9",
    "react-i18next": "^11.5.0",
    "react-native": "^0.63.2",
    "react-native-admob": "https://github.com/vezure/react-native-admob#78356674caa5148921ff9f35f0a23eb4e29ee498",
    "react-native-agora": "^3.0.1-rc.5",
    "react-native-animatable": "^1.3.3",
    "react-native-branch": "^5.0.0",
    "react-native-calendar-strip": "^2.0.6",
    "react-native-chart-kit": "^6.4.1",
    "react-native-countdown-circle-timer": "^2.3.10",
    "react-native-countdown-component": "^2.7.1",
    "react-native-country-picker-modal": "^1.10.0",
    "react-native-credit-card-input": "^0.4.1",
    "react-native-dotenv": "^2.4.2",
    "react-native-fast-image": "^8.3.2",
    "react-native-gesture-handler": "^1.6.1",
    "react-native-get-random-values": "^1.4.0",
    "react-native-gifted-chat": "^0.14.1",
    "react-native-image-picker": "^2.3.1",
    "react-native-image-placeholder": "^1.0.14",
    "react-native-image-with-placeholder": "^0.1.1",
    "react-native-keep-awake": "^4.0.0",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-mo-orientation": "^0.1.10",
    "react-native-modal": "^11.5.6",
    "react-native-modal-datetime-picker": "^9.0.0",
    "react-native-modalize": "^2.0.6",
    "react-native-modalize-webview": "^1.0.0",
    "react-native-permissions": "^2.2.0",
    "react-native-read-more-text": "^1.1.2",
    "react-native-reanimated": "^1.7.1",
    "react-native-safe-area-context": "^0.7.3",
    "react-native-screens": "^2.4.0",
    "react-native-simple-bottom-sheet": "^1.0.1",
    "react-native-slider": "^0.11.0",
    "react-native-snap-carousel": "^3.9.0",
    "react-native-splash-screen": "^3.2.0",
    "react-native-svg": "^12.1.0",
    "react-native-textinput-effects": "^0.6.1",
    "react-native-uuid": "^1.4.9",
    "react-native-video": "^4.4.5",
    "react-native-vlc-player": "^0.2.3",
    "react-native-webview": "^9.4.0",
    "react-redux": "^7.2.0",
    "redux": "^4.0.5",
    "redux-logger": "^3.0.6",
    "redux-persist": "^6.0.0",
    "redux-saga": "^1.1.3",
    "rn-fetch-blob": "^0.12.0",
    "rn-orientation-view": "^1.0.3",
    "socket.io-client": "2.1.1",
    "styled-components": "^5.2.0",
    "timeago.js": "^4.0.2",
    "underscore": "^1.10.2",
    "uuid": "^8.0.0",
    "xendit-js-node": "^1.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.6.2",
    "@babel/runtime": "^7.6.2",
    "@react-native-community/eslint-config": "^0.0.5",
    "@types/bluebird": "^3.5.32",
    "@types/jest": "^24.0.24",
    "@types/react-native": "^0.60.25",
    "@types/react-native-read-more-text": "^1.0.0",
    "@types/react-test-renderer": "16.9.1",
    "@types/redux-logger": "^3.0.8",
    "@types/socket.io-client": "^1.4.32",
    "@typescript-eslint/eslint-plugin": "^2.12.0",
    "@typescript-eslint/parser": "^2.12.0",
    "babel-jest": "^24.9.0",
    "eslint": "^7.9.0",
    "eslint-config-airbnb": "^18.2.0",
    "eslint-config-prettier": "^6.11.0",
    "eslint-plugin-prettier": "^3.1.4",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.56.0",
    "prettier": "^2.1.2",
    "react-native-version": "^4.0.0",
    "react-test-renderer": "16.9.0",
    "typescript": "^3.7.3"
  },
  "jest": {
    "preset": "react-native",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json",
      "node"
    ]
  }
}