【问题标题】:Gradle Sync Failed - Android Studio 2.3.1Gradle 同步失败 - Android Studio 2.3.1
【发布时间】:2017-04-05 23:04:18
【问题描述】:

我的代码在更新前运行良好。但是我更新到2.3.1之后就开始报如下错误,

    Error: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:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
<a href="syncProject">Re-download dependencies and sync project (requires network)</a></li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
<a href="stopGradleDaemons">Stop Gradle build processes (requires restart)</a></li><li>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.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

请帮忙。

【问题讨论】:

标签: java android


【解决方案1】:

终于找到了解决办法。

指定 gradle 版本。您可以在 Android Studio 的 File > Project Structure > Project 菜单或顶级 build.gradle 文件中为 Gradle 版本指定 Android 插件。该插件版本适用于该 Android Studio 项目中构建的所有模块。以下示例从 build.gradle 文件将 Gradle 的 Android 插件设置为 2.3.1 版本:

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

来源:enter link description here

【讨论】:

  • 将类路径更新为最新的兼容 gradle 版本(在我的例子中:classpath 'com.android.tools.build:gradle:2.4.0-alpha7')并将 buildToolsVersion 更新为 25 解决了问题。谢谢!
猜你喜欢
  • 1970-01-01
  • 2016-05-18
  • 2023-04-09
  • 2017-11-07
  • 2019-06-07
  • 2019-01-18
  • 2016-02-04
  • 2014-07-03
  • 2014-04-04
相关资源
最近更新 更多