包 com.reactnativenavigation 不存在 [英] package com.reactnativenavigation does not exist

查看:116
本文介绍了包 com.reactnativenavigation 不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 React Native 的初学者.现在我正在尝试集成 https://wix.github.io/react-native-navigation/#/ 库到我的 react-native 应用程序.目前,我只针对 Android 平台.

I am a beginner in react native. Right now I am trying to integrate https://wix.github.io/react-native-navigation/#/ library to my react-native application. for now, I am targeting only the Android platform.

我已经执行了文档中提到的所有步骤,但是当我尝试使用 react-native run-android 在应用程序上运行时,它给了我以下错误.

I have performed all the steps that are mentioned in the documentation but when I tried to run on an application using react-native run-android it gives me the below error.

错误:com.reactnativenavigation 包不存在

我理解错误的意思是说这个包不存在于我的项目中,但我从 npm 安装的这个包存在于节点模块中.

I understand the meaning of error it is saying that this package doesn't exist in my project but this package I installed from npm and it exists in the node module.

我使用的是最新版本的 Nodejs 和 npm,下面是 package.json 依赖项.

I am using the latest version of Nodejs and npm and below is the package.json dependency.

 "dependencies": {
    "react": "16.8.3",
    "react-native": "^0.59.6",
    "react-native-navigation": "^2.18.2",
    "react-native-vector-icons": "^6.4.2",
    "react-redux": "^7.0.2",
    "redux": "^4.0.1"
},
"devDependencies": {
    "@babel/core": "^7.4.3",
    "@babel/runtime": "^7.4.3",
    "babel-jest": "^24.7.1",
    "jest": "^24.7.1",
    "metro-react-native-babel-preset": "^0.53.1",
    "react-test-renderer": "16.8.3"
},

完全错误:

E:\data\code\practise\react-native\reactNativeStart\android\app\src\main\java\com\reactnativestart\MainActivity.java:19: error: package com.reactnativenavigation does not exist
import com.reactnativenavigation.NavigationActivity;
                                ^
E:\data\code\practise\react-native\reactNativeStart\android\app\src\main\java\com\reactnativestart\MainActivity.java:21: error: cannot find symbol
public class MainActivity extends NavigationActivity {
                                  ^
  symbol: class NavigationActivity
E:\data\code\practise\react-native\reactNativeStart\android\app\src\main\java\com\reactnativestart\MainApplication.java:12: error: package com.reactnativenavigation does not exist
import com.reactnativenavigation.NavigationApplication;
                                ^
E:\data\code\practise\react-native\reactNativeStart\android\app\src\main\java\com\reactnativestart\MainApplication.java:13: error: package com.reactnativenavigation.react does not exist
import com.reactnativenavigation.react.NavigationReactNativeHost;
                                      ^
E:\data\code\practise\react-native\reactNativeStart\android\app\src\main\java\com\reactnativestart\MainApplication.java:14: error: package com.reactnativenavigation.react does not exist
import com.reactnativenavigation.react.ReactGateway;
                                      ^
E:\data\code\practise\react-native\reactNativeStart\android\app\src\main\java\com\reactnativestart\MainApplication.java:20: error: cannot find symbol
public class MainApplication extends NavigationApplication {
                                     ^
  symbol: class NavigationApplication
E:\data\code\practise\react-native\reactNativeStart\android\app\src\main\java\com\reactnativestart\MainApplication.java:54: error: cannot find symbol
    protected ReactGateway createReactGateway() {
              ^
  symbol:   class ReactGateway
  location: class MainApplication
E:\data\code\practise\react-native\reactNativeStart\android\app\src\main\java\com\reactnativestart\MainApplication.java:53: error: method does not override or implement a method from a supertype
  @Override
  ^
E:\data\code\practise\react-native\reactNativeStart\android\app\src\main\java\com\reactnativestart\MainApplication.java:55: error: cannot find symbol
        ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
                                   ^
  symbol:   class NavigationReactNativeHost
  location: class MainApplication
E:\data\code\practise\react-native\reactNativeStart\android\app\src\main\java\com\reactnativestart\MainApplication.java:56: error: method does not override or implement a method from a supertype
            @Override
            ^
E:\data\code\practise\react-native\reactNativeStart\android\app\src\main\java\com\reactnativestart\MainApplication.java:61: error: cannot find symbol
        return new ReactGateway(this, isDebug(), host);
                   ^
  symbol:   class ReactGateway
  location: class MainApplication
E:\data\code\practise\react-native\reactNativeStart\android\app\src\main\java\com\reactnativestart\MainApplication.java:64: error: method does not override or implement a method from a supertype
    @Override
    ^
E:\data\code\practise\react-native\reactNativeStart\android\app\src\main\java\com\reactnativestart\MainApplication.java:77: error: method does not override or implement a method from a supertype
    @Override
    ^
13 errors

推荐答案

我不认为降级是一个好的解决方案.我遇到了这个问题,我假设您仍在使用 React Native 60+(在我的情况下为 0.61).我通过忽略除 RN 60 之外的所有以前版本的风格来解决它.我相信这与忽略 if 块中列出的所有版本的插件有关.

I don't believe downgrading is a good solution. I had this issue, I am assuming you are still on React Native 60+ (0.61 in my case). I solved it by ignoring flavours to all previous versions except for RN 60. I believe it has something to do with plugins for all the versions listed in the if block being ignored.

所以在你的 android/build.gradle 中有下面的代码

So in your android/build.gradle have the code below down the bottom

subprojects { subproject ->
    afterEvaluate {
        if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
            android {
                variantFilter { variant ->
                    def names = variant.flavors*.name
                    if (
                            names.contains("reactNative51") ||
                            names.contains("reactNative55") ||
                            names.contains("reactNative56") ||
                            names.contains("reactNative57") ||
                            names.contains("reactNative57_5") 
                            // names.contains("reactNative60")
                    ) {
                        setIgnore(true)
                    }
                }
            }
        }
    }
}

MainApplication.java 中出现无法识别的符号后,您可能会遇到错误,其中文档也提供了错误的信息.

You may run into an error after about unrecognised symbols in MainApplication.java where the doc is also providing the wrong information.

在您的 MainApplication.java 下面应该是您的 MainApplication 方法.我已将 getPackages() 方法更改为 RN 的原始方法,因为在 RN 60 中,RNN 使用的方法存在类型错误

In your MainApplication.java below should be your MainApplication Method. I have changed the getPackages() method to RN's original method as in RN 60 the method that RNN uses has type errors

public class MainApplication extends NavigationApplication {

    @Override
    protected ReactGateway createReactGateway() {
        ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
            @Override
            protected String getJSMainModuleName() {
                return "index";
            }
        };
        return new ReactGateway(this, isDebug(), host);
    }

    @Override
    public boolean isDebug() {
        return BuildConfig.DEBUG;
    }

    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;
    }

    @Override
    public List<ReactPackage> createAdditionalReactPackages() {
        return getPackages();
    }
}

这篇关于包 com.reactnativenavigation 不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆