Android Studio 不支持的 Gradle 插件版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24599785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:28:31  来源:igfitidea点击:

Android Studio Unsupported Version of Gradle Plugin

androidandroid-studiogradleandroid-gradle-pluginbuild.gradle

提问by Patrick Brennan

Similar to the question asked here : Android Studio unsupported version of gradle but I'm using a compatible version, but the answer there does not fix the problem for me.

类似于这里提出的问题:Android Studio unsupported version of gradle but I'm using a compatible version,但那里的答案并没有解决我的问题。

I am using Android Studio Beta 0.8.1 running under Ubuntu 14.04 LTS. I am trying to import a project which is shared with my team, but when I clone the project and attempt to build it, I get this error:

我正在使用在 Ubuntu 14.04 LTS 下运行的 Android Studio Beta 0.8.1。我正在尝试导入与我的团队共享的项目,但是当我克隆该项目并尝试构建它时,出现此错误:

Error:The project is using an unsupported version of the Android Gradle
plug-in (0.11.2) <a href="fixGradleElements">Fix plug-in version and re-import
project</a>

When I click the link, I get this error:

当我单击链接时,出现此错误:

12:21:30 PM Quick Fix Failed
         Unable to find any references to the Android Gradle plug-in in build.gradle files.
         Please click the link to perform a textual search and then update the build files manually.

Here is the relevant section of my build.gradle file:

这是我的 build.gradle 文件的相关部分:

buildscript {
  ...
  dependencies {
      classpath 'com.android.tools.build:gradle:0.11.+'
  } 
}

I have manually installed a recent version of Gradle in an attempt to rectify this problem (Ubuntu really only wants to let me have version 1.4, but our project is configured for Gradle 1.11+. Here is the output of "gradle -v":

我手动安装了最新版本的 Gradle 试图解决这个问题(Ubuntu 真的只想让我有 1.4 版,但我们的项目是为 Gradle 1.11+ 配置的。这是“gradle -v”的输出:

------------------------------------------------------------
Gradle 1.11
------------------------------------------------------------

Build time:   2014-02-11 11:34:39 UTC
Build number: none
Revision:     a831fa866d46cbee94e61a09af15f9dd95987421

Groovy:       1.8.6
Ant:          Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy:          2.2.0
JVM:          1.8.0_05 (Oracle Corporation 25.5-b02)
OS:           Linux 3.13.0-30-generic amd64

I tried to set Android Studio to use the local Gradle installation (File > Settings > Gradle > Use local gradle distribution), but this only yields an error that a given task can't be found in the root project. (?)

我试图将 Android Studio 设置为使用本地 Gradle 安装(文件 > 设置 > Gradle > 使用本地 gradle 分发),但这只会产生一个错误,即在根项目中找不到给定的任务。(?)

When I build the project from the command line with the command "./gradlew clean assembleDebug", it builds perfectly and I am able to install and run the APK.

当我使用命令“./gradlew clean assembleDebug”从命令行构建项目时,它完美构建并且我能够安装和运行APK。

I don't understand what I'm doing wrong, or how to fix it. Any clues would be deeply appreciated!

我不明白我做错了什么,或者如何解决它。任何线索将不胜感激!

回答by Gabriele Mariotti

Android Studio 0.8.1 requires the gradle-plugin 0.12.

Android Studio 0.8.1 需要 gradle-plugin 0.12。

buildscript {
  ...
  dependencies {
      classpath 'com.android.tools.build:gradle:0.12.+'
  } 
}

Check this answer for compatibility:

检查此答案的兼容性:

Android Studio Gradle issue upgrading to version 0.5.0 - Gradle Migrating From 0.8 to 0.9 - Also Android Studio upgrade to 0.8.1

Android Studio Gradle 问题升级到 0.5.0 版 - Gradle 从 0.8 迁移到 0.9 - Android Studio 也升级到 0.8.1

回答by Patrick Brennan

Now I understand what I was doing wrong. The newer version of Andoid Studio which I have installed does not support the gradle 0.11.* plugin. The fix is to update all of my build.gradle files thus:

现在我明白我做错了什么。我安装的较新版本的 Andoid Studio 不支持 gradle 0.11.* 插件。解决方法是更新我所有的 build.gradle 文件,因此:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}

So I have changed the 'gradle:0.11.+' to 'gradle:0.12.+'.

所以我已经将 'gradle:0.11.+' 更改为 'gradle:0.12.+'。

By opening the build.gradle file(s) and looking at the error messages which were displayed on the relevant lines, I could see that they were muchmore useful than the error messages which I was originally confronted with. I was looking for some way to upgrade my gradle installation, or my gradle plugin in Android Studio. What Android Studio wanted was for me to update the build file to specify a different gradle plugin version. I don't understand why that was really necessary - I haven't changed a thing in the source code! - but Android Studio will now happily build and run my project.

通过打开的build.gradle文件(S),看着它被显示在相关线路的错误信息,我看得出来,他们是很多比我最初面临着错误信息更有用。我正在寻找某种方法来升级我的 gradle 安装,或者我在 Android Studio 中的 gradle 插件。Android Studio 想要的是让我更新构建文件以指定不同的 gradle 插件版本。我不明白为什么这真的很有必要——我没有改变源代码中的任何东西!- 但 Android Studio 现在可以愉快地构建和运行我的项目。

Thanks to Gabriele Mariotti for clarification.

感谢 Gabriele Mariotti 的澄清。

回答by Xiao

I also got this error on Linux Mint 17.

我在 Linux Mint 17 上也遇到了这个错误。

I had installed gradle from the Ubuntu repositories but it was version 1.4. So I downloaded 1.10 using the ppa:

我已经从 Ubuntu 存储库安装了 gradle,但它是 1.4 版。所以我使用 ppa 下载了 1.10:

sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle-1.10

NoteDon't do sudo apt-get install gradle, as the newest version (2.x at this time) is also rejected by Android Studio

注意不要这样做sudo apt-get install gradle,因为最新版本(此时为 2.x)也被 Android Studio 拒绝