更新到3.0后,Gradle构建失败 [英] Gradle build failing after update to 3.0

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

问题描述

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


错误:原因:org.gradle.api.internal.tasks.DefaultTaskInputs $ TaskInputUnionFileCollection无法转换为org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection
此意外错误的可能原因包括:

  • Gradle的依赖关系缓存可能已损坏(有时会在网络连接超时。)
    重新下载依赖项并同步项目(需要网络)
  • Gradle构建过程(守护进程)的状态可能已损坏。停止所有的Gradle守护进程可能会解决这个问题。
    停止Gradle构建过程(需要重新启动)
  • 您的项目可能使用与项目中其他插件或项目请求的Gradle版本不兼容的第三方插件。
在发生损坏的Gradle进程的情况下,您也可以尝试关闭IDE,然后查杀所有Java进程。


我搜索了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:

Error:Cause: org.gradle.api.internal.tasks.DefaultTaskInputs$TaskInputUnionFileCollection cannot be cast to org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection Possible causes for this unexpected error include:

  • Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)
  • The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart)
  • Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

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构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆