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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22252956/
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 05:43:10  来源:igfitidea点击:

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

androidgradleandroid-studioandroid-gradle-pluginbuild.gradle

提问by Cedric Simon

After upgrade message states:

升级后消息指出:

Failed to refresh Gradle project 'XXX'
The project is using an unsupported version of the Android Gradle plug-in (0.8.3).
Version 0.9.0 introduced incompatible changes in the build language.
Please read the migration guide to learn how to update your project.

Same kind of issue after upgrade to Android Studio to version >= 0.8.0

升级到 Android Studio 到版本 >= 0.8.0 后的同类问题

回答by Gabriele Mariotti

Android Studio 0.5.0requires gradle-plugin 0.9.0

Android Studio 0.5.0需要gradle-plugin 0.9.0

The gradle-plugin 0.9.0works with Gradle 1.10 or Gradle 1.11

gradle-plugin 0.9.0适用于Gradle 1.10 或 Gradle 1.11

Modify your build.gradle script as suggested by Cedric.

按照 Cedric 的建议修改您的 build.gradle 脚本。

There is a relation between gradle-plugin and the gradle version.For example

gradle-plugin 和 gradle 版本之间存在关系。例如

UPDATED TO 27/11/2015:

更新至 27/11/2015

com.android.tools.build:gradle:0.6.+   -> gradle 1.8
com.android.tools.build:gradle:0.7.+   -> gradle 1.9
com.android.tools.build:gradle:0.8.+   -> gradle 1.9/1.10
com.android.tools.build:gradle:0.9.+   -> gradle 1.10/1.11
com.android.tools.build:gradle:0.10.+  -> gradle 1.10/1.11/1.12
com.android.tools.build:gradle:0.11.+  -> gradle 1.10/1.11/1.12
com.android.tools.build:gradle:0.12.+  -> gradle 1.10/1.11/1.12
com.android.tools.build:gradle:0.13.+  -> gradle 2.1
com.android.tools.build:gradle:0.14.+  -> gradle 2.1
com.android.tools.build:gradle:1.0.+   -> gradle 2.2.1-2.3
com.android.tools.build:gradle:1.1.+   -> gradle 2.2.1-2.3
com.android.tools.build:gradle:1.2.+   -> gradle 2.2.1+
com.android.tools.build:gradle:1.3.+   -> gradle 2.2.1+
com.android.tools.build:gradle:1.3.+   -> gradle 2.2.1+
com.android.tools.build:gradle:1.5.+   -> gradle 2.2.1+
com.android.tools.build:gradle:2.0.+   -> gradle 2.10.0+

You can find gradle version used in your project in the file gradle/wrapper/gradle-wrapper.properties

您可以在文件中找到项目中使用的 gradle 版本 gradle/wrapper/gradle-wrapper.properties

Also there is a relation between gradle-plugin and the IDE version.

gradle-plugin 和 IDE 版本之间也有关系。

Android Studio 0.3.x  -> gradle-plugin 0.6
Android Studio 0.4.x  -> gradle-plugin 0.7
Android Studio 0.4.3+ -> gradle-plugin 0.8
Android Studio 0.5.x  -> gradle-plugin 0.9
Android Studio 0.5.8  -> gradle-plugin 0.9.+ or 0.10.+
Android Studio 0.5.9  -> gradle-plugin 0.9.+ or 0.10.4+
Android Studio 0.6.x  -> gradle-plugin 0.11.+
Android Studio 0.8.x  -> gradle-plugin 0.12.+
Android Studio 0.8.11+  -> gradle-plugin 0.13.+ / gradle-plugin 0.12.+
Android Studio 0.9.x  -> gradle-plugin 0.14.+
Android Studio 1.0.0  -> gradle-plugin 1.0.0
Android Studio 1.1.x  -> gradle-plugin 1.0.0/ 1.1.x / 1.2.x
Android Studio 1.2.x  -> gradle-plugin 1.0.0/ 1.1.x / 1.2.x
Android Studio 1.3.x  -> gradle-plugin 1.0.0/ 1.1.x / 1.2.x / 1.3.x 
Android Studio 1.4.x  -> gradle-plugin 1.0.0/ 1.1.x / 1.2.x / 1.3.x 
Android Studio 1.5.x  -> gradle-plugin 1.0.0/ 1.1.x / 1.2.x / 1.3.x / 1.5.x
Android Studio 2.0.x  -> gradle-plugin 2.0.0

 Also gradle 1.12 requires Android Studio 0.5.8+

For updated news you can check this link: http://tools.android.com/recent
For updated doc about the gradle plugin check here.

有关更新的新闻,您可以查看此链接:http:
//tools.android.com/recent 有关 gradle 插件的更新文档,请在此处查看

If you change your plugin version, check compatibility, and then click sync project with your gradle files.It will download a new plugin version if you need it.

如果您更改了插件版本,请检查兼容性,然后单击将项目与您的 gradle 文件同步。如果您需要,它会下载新的插件版本。

回答by Cedric Simon

To fix it, open file called build.gradlein the project root, and change gradle version there to 0.9.+.

要修复它,打开build.gradle在项目根目录中调用的文件,并将那里的 gradle 版本更改为 0.9.+。

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

To be repeated for each project ;(

为每个项目重复;(

If you then get a message like "Unable to load class 'org.gradle.api.artifacts.result.ResolvedComponentResult".

如果您随后收到“无法加载类”之类org.gradle.api.artifacts.result.ResolvedComponentResult的消息。

Go to you project_folder/gradle/wrapperdirectory and edit Unable to load class 'org.gradle.api.artifacts.result.ResolvedComponentResult'.file changing the distributionUrlto

转到您的project_folder/gradle/wrapper目录并编辑Unable to load class 'org.gradle.api.artifacts.result.ResolvedComponentResult'.文件更改distributionUrl

distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip

After upgrade to version 0.8.1 (full download and copy SDK folder over), had to have new version of gradle installed by IDE (using the "Fix it" link a couple of time :S ), and modifing the "android" section of the gradle file in project folder from 19.0 to 19.1, as below: buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.12.+' } } apply plugin: 'android'

升级到 0.8.1 版(完整下载并复制 SDK 文件夹)后,必须通过 IDE 安装新版本的 gradle(使用“Fix it”链接几次:S),并修改“android”部分从 19.0 到 19.1 的项目文件夹中的 gradle 文件,如下所示: buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.12.+' } } apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion '19.1.0'

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 19
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:19.1.+'
    compile 'com.android.support:support-v4:19.1.0'
}

回答by lucidbrot

I had the same error, but already had

我有同样的错误,但已经有

classpath 'com.android.tools.build:gradle:0.9.+'

set like this, as Cedric Simon suggested. Thanks to the comment of mattblang, I tried to change it to 0.9.0 and refreshed it

像塞德里克西蒙建议的那样设置。感谢mattblang的评论,我试着改成0.9.0刷新一下

for those who don't know, where the refresh button is, look below:

对于那些不知道刷新按钮在哪里的人,请看下面:

enter image description here

在此处输入图片说明

Afterwards I tried what happens when I change it back to 0.9.+ and refresh again...and it still works.

之后,我尝试将其改回 0.9.+ 并再次刷新时会发生什么……它仍然有效。

So I assume, only pressing the refresh button would have sufficed.

所以我假设,只要按下刷新按钮就足够了。

回答by AnanThDev

I faced Same problem Migrating into gradle version 1.0.0.. This solution helps me and save the date..

我遇到了同样的问题迁移到 gradle 版本 1.0.0 .. 这个解决方案帮助我并保存日期..

Update Plugin and Gradle Version Numbers

更新插件和 Gradle 版本号

The Android Gradle plugin version is typically listed in the top level build.gradlefile in the project, and can be updated as follows:

Android Gradle 插件版本通常列在项目的顶层build.gradle文件中,可以按如下方式更新:

Let me consider i have version 0.8.. show my build.gradle(project root folder/build.gradle) shows

让我考虑一下我有 0.8 版.. 显示我的 build.gradle(project root folder/build.gradle) 显示

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

依赖项 { 类路径 'com.android.tools.build:gradle:0.8.+' }

remove the old version(0.8) and add new version 1.0.0 like this

删除旧版本(0.8)并像这样添加新版本1.0.0

dependencies { classpath 'com.android.tools.build:gradle:1.0.0' }

依赖项 { 类路径 'com.android.tools.build:gradle:1.0.0' }

And also change the gradle/wrapper/gradle-wrapper.properties:

还要更改gradle/wrapper/gradle-wrapper.properties

remove the old distributionUrl and add new url

删除旧的 distributionUrl 并添加新的 url

distributionUrl=http://services.gradle.org/distributions/gradle-2.2.1-all.zip

distributionUrl=http://services.gradle.org/distributions/gradle-2.2.1-all.zip

and change the runProguard in project root/app/build.gradle

并更改项目 root/app/build.gradle 中的 runProguard

BEFORE:

前:

buildTypes { release { runProguard true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }

buildTypes { release { runProguard true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }

AFTER:

后:

buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }

buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }

For more information : Migrating gradle Project(click here)

有关更多信息:迁移 gradle 项目(单击此处)

回答by user827096

Android Studio version 1.0.2 The idea of tight coupling between IDE version and build version is bad.

Android Studio version 1.0.2 IDE 版本和构建版本之间紧密耦合的想法很糟糕。

Android Studio 1.0.2. Gralde plugin 1.0.+ gradle.properties, distribution URL=http://services.gradle.org/distributions/gradle-2.2.1-bin.zip

安卓工作室 1.0.2。Gralde 插件 1.0.+ gradle.properties,分发 URL=http://services.gradle.org/distributions/gradle-2.2.1-bin.zip

回答by codercat

The most simple Android project has the following build.gradle:

最简单的Android项目有如下build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.0'
    }
}

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"
}

There are 3 main areas to this Android build file:

此 Android 构建文件有 3 个主要区域:

new-build-system user-guide

新建系统用户指南

回答by GR Envoy

When I updated to Android Studio 1.0 I found that I need to update to use 1.0.0 version of gradle.

当我更新到 Android Studio 1.0 时,我发现我需要更新以使用 1.0.0 版本的 gradle。

I had

我有

  dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0-rc2'

I changed it to remove the "-rc2"

我将其更改为删除“-rc2”

  dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'

回答by pierre rentheitroad

hmm I'm getting this error when I try to add this dependency.

嗯,当我尝试添加此依赖项时出现此错误。

Error:(22) A problem occurred evaluating project ':app'.

错误:(22) 评估项目“:app”时出现问题。

Could not find method classpath() for arguments [com.android.tools.build:gradle:0.9.+] on project ':app'.

无法在项目“:app”上找到参数 [com.android.tools.build:gradle:0.9.+] 的方法 classpath()。

Ok solved it. This line should be part of the build.gradle "in the project root" as stated above, but I did not recognize. Updating the Build tools to 19.03 actually inserted it in automatically.

好的解决了它。如上所述,这一行应该是“项目根目录中”的 build.gradle 的一部分,但我不认识。将构建工具更新到 19.03 实际上是自动插入的。