android – 更新到3.0后Gradle构建失败

我最近将我的项目的gradle版本从2.14.1更新到3.0.从那时起,每次出现此错误时,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.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

搜索了谷歌,发现了一些像this一样的解决方案,但没有任何工作.有谁知道如何修理它?

解决方法:

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

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

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

然后,您可以运行gradle任务,gradle将下载您需要的所有内容.

在2016年9月19日发布Android Studio 2.2之后,最新版本的构建工具为2.2.0.所以你可以修理它:

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

由于Android Studio 2.4 stable还没有准备好发布(2017年5月4日),最新的稳定版构建工具是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构建在更新到3.0之后失败,但我强烈建议你使用谷歌推荐的最新构建工具)

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

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()

 repositories {
    jcenter()
    //mavenCentral()
}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...