gpt4 book ai didi

android - 包 com.reactnativenavigation 不存在

转载 作者:太空狗 更新时间:2023-10-29 15:25:07 27 4
gpt4 key购买 nike

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

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

错误:包 com.reactnativenavigation 不存在

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

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

 "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 之外的所有先前版本的 flavor 来解决它。我相信它与 if block 中列出的所有版本的插件被忽略有关。

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

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 中出现无法识别的符号后,您可能会遇到错误,而文档也提供了错误的信息。

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

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

关于android - 包 com.reactnativenavigation 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55849097/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com