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

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

问题描述

我最近将项目的 gradle 版本从 2.14.1 更新到 3.0.从那时起,gradle 构建每次都失败并出现此错误:

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:

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

  • Gradle 的依赖项缓存可能已损坏(这有时发生在网络连接超时之后.)重新下载依赖项并同步项目(需要网络)
  • Gradle 构建进程(守护进程)的状态可能已损坏.停止所有 Gradle 守护进程可能会解决这个问题.停止 Gradle 构建过程(需要重新启动)
  • 您的项目可能正在使用第三方插件,该插件与项目中的其他插件或项目请求的 Gradle 版本不兼容.
  • 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.

    我搜索了谷歌并找到了一些解决方案,例如这个,但没有在职的.有大佬知道怎么解决吗?

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

    推荐答案

    将您的 gradle 构建工具升级到最新版本.

    Upgrade your gradle build tools to the latest version.

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

    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'
    }
    

    然后你可以运行 gradle tasks 并且 gradle 会下载你需要的一切.

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

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

    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'
    }
    

    由于 Android Studio 2.4 稳定版尚未准备好发布(2017 年 5 月 4 日),构建工具的最新稳定版本为 2.3.1.

    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'
    }
    

    如果您将此构建工具版本更新为 2.3.* ,您还应该在/yourProjectRoot/gradle/wrapper/gradle-wrapper.properties 文件中将 gradle 包装器版本更新为 3.3.(我知道它不匹配问题Gradle build failed after update to 3.0,但我强烈建议您使用谷歌推荐的最新构建工具)

    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)

    顺便说一句:构建工具的 2.3.1 版仅存在于 jCenter 上,而不存在于 MavenCentral,因此如果您在终端中运行 gradlew 命令行时遇到以下错误

    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
    

    用 jcenter() 替换 mavenCentral() 就像

    just replace mavenCentral() with jcenter() like

     repositories {
        jcenter()
        //mavenCentral()
    }
    

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

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