7

我刚刚更新到 Android Studio 4.0 并尝试构建我的项目。我不断收到以下错误

Unsupported method: AndroidArtifact.getBuildConfigFields().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model.

我已经在使用最新版本的 Gradle 和 Gradle Plugin

摇篮版本:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-milestone-1-all.zip

Gradle 插件工具版本:

classpath 'com.android.tools.build:gradle:4.1.0-alpha10'

此问题的任何解决方案或修复程序都会有所帮助。提前致谢。

4

2 回答 2

6

使用 Android Studio 4.1 预览版或类路径 'com.android.tools.build:gradle:4.0.0'

于 2020-06-06T16:59:06.640 回答
2

这通常是由于您的 Android Studio 版本与 Android Gradle 插件不匹配所致。

您可以在第一次打开时在项目选择窗口中找到 Android Studio 的版本(或者在 Mac 上的“Android Studio > About Android Studio”中,其他平台上的类似位置)。例如,您可能使用的是 Android Studio 4.0.1。

您可以在顶级build.gradle文件中找到您项目的 Android Gradle 插件版本。

您应该找到类似以下内容:

buildscript {
    [...]
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        [...]
    }
    [...]
}

您需要确保两个版本号匹配(在这种情况下它们匹配)。

于 2020-08-28T07:24:39.333 回答