微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐