本文介绍了更新到3.0后,Gradle构建失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我的项目的gradle版本从2.14.1更新到了3.0。从那时起,每次出现这个错误时,gradle构建都会失败:
$ b

我搜索了google并找到了一些解决方案,如,但没有任何工作。有谁知道如何解决它?

解决方案

$ b $升级您的gradle构建工具到最新版本。 b

执行此操作的一个简单方法是在您的 build.gradle 文件中添加最新版本的构建工具作为依赖项,例如:

 依赖关系{
classpath'com.android.tools.build:gradle:2.2.0-beta1'

$ / code>

然后你可以运行 gradle tasks 和gradle将下载您需要的所有内容。

在2016年9月19日发布Android Studio 2.2后,最新版本的构建工具为2.2.0。所以你可以通过以下方式修复它:

 依赖关系{
classpath'com.android.tools.build:gradle:2.2 .0'
}

Android Studio 2.4稳定版尚未发布4 2017),构建工具的最新稳定版本是2.3.1。

 依赖关系{
classpath'com。 android.tools.build:gradle:2.3.1'
}

如果你更新了这个将工具版本构建为2.3。*,您还应该在/yourProjectRoot/gradle/wrapper/gradle-wrapper.properties文件中将gradle wrapper版本更新为3.3。 (我知道它不是匹配问题在更新到3.0之前Gradle构建失败,但我强烈建议您使用google推荐的最新构建工具)



BTW:版本2.3.1的构建工具只存在于jCenter,而不是MavenCentral,所以如果在终端运行gradlew命令行时遇到以下错误:

 找不到com.android.tools.build:gradle:2.3.1。 
在以下位置搜索:
https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.3.1/gradle-2.3.1.pom
https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.3.1/gradle-2.3.1.jar

只需使用jcenter()替换mavenCentral()就像

  repositories {
jcenter()
// mavenCentral()
}


I've recently updated the gradle version of my project from 2.14.1 to 3.0. Since then the gradle build is failing every time with this error:

I've searched google and found some solutions like this one but nothing is working. Does anyone know how to fix it?

解决方案

Upgrade your gradle build tools to the latest version.

One easy way to do this is to add the latest version of the build tools as a dependency in your build.gradle file, for example:

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0-beta1'
}

You can then run gradle tasks and gradle will download everything you need.

After Android Studio 2.2 stable released on Sep 19 2016 , the latest version of the build tools is 2.2.0 . So you can fix it by :

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

As Android Studio 2.4 stable is not ready to release yet (May 4 2017), the latest stable version of build tools is 2.3.1 .

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

If you update this build tools version to 2.3.* , you should also update gradle wrapper version to 3.3 in /yourProjectRoot/gradle/wrapper/gradle-wrapper.properties file. (i know it is not matching question Gradle build failing after update to 3.0, but i strongly suggest you to use latest build tool as google recommended)

BTW: version 2.3.1 of build tool is only exist on jCenter, not MavenCentral, so if you run into error below when run gradlew command line in terminal

Could not find com.android.tools.build:gradle:2.3.1.
 Searched in the following locations:
     https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.3.1/gradle-2.3.1.pom
     https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.3.1/gradle-2.3.1.jar

just replace mavenCentral() with jcenter() like

 repositories {
    jcenter()
    //mavenCentral()
}

这篇关于更新到3.0后,Gradle构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 10:19
查看更多