升级 React Native 版本。

7

将React Native版本从0.63.3升级到最新版本后,我遇到了以下错误:

> Could not resolve all files for configuration ':classpath'.
   > Could not find com.facebook.react:react-native-gradle-plugin:.
     Required by:
         project :

以下是我build.gradle文件中的依赖关系:

   dependencies {
        classpath("com.android.tools.build:gradle:7.0.4")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("de.undercouch:gradle-download-task:4.1.2")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

有人能够向我解释这个吗?如果你能帮忙,那将不胜感激!

3个回答

10
@RamaProg所提供的Github问题确实提供了一些见解,但它是在构建react-native源代码的情况下。我认为这个问题是在0.68.1成为稳定的公共版本之前创建的。
根据这里的升级指南:https://react-native-community.github.io/upgrade-helper/?from=0.67.4&to=0.68.1
建议在settings.gradle中添加以下内容:
includeBuild('../node_modules/react-native-gradle-plugin')
if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true") {
    include(":ReactAndroid")
    project(":ReactAndroid").projectDir = file('../node_modules/react-native/ReactAndroid')
}

这个更改解决了我的问题。


3

我最近在升级到v68+后遇到了这个问题。 当我手动添加react-native-gradle-plugin包时,问题得到解决。

yarn add react-native-gradle-plugin

此包未包含在升级助手中。


2
根据这个RN问题:https://github.com/facebook/react-native/issues/33067 你的问题可能会通过进入你的settings.gradle并替换以下内容来得到解决:
includeBuild('../node_modules/react-native/packages/react-native-gradle-plugin')

使用:

includeBuild('../node_modules/react-native/packages/react-native-gradle-plugin') {
    dependencySubstitution {
        substitute(module("com.facebook.react:react-native-gradle-plugin")).using(project(":"))
    }
}

问题在于您正在使用旧版本的仓库,因此维基已更新为使用最新的主要版本。从不同版本的源代码构建通常不受支持(即您需要自己解决问题),因为存在这些类型的不兼容性,并且我们无法为所有可能的RN版本/分支提供说明。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接