简体   繁体   English

升级到Android Studio 2.3后无法同步Gradle

[英]Can't sync Gradle after upgrading to Android Studio 2.3

This happens every so often, but I can't seem to resolve it this time. 这种情况经常发生,但这次我似乎无法解决它。 Project builds fine from the command line. 项目从命令行构建良好。 This is the error: 这是错误:

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: 此意外错误的可能原因包括:

  • Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network) Gradle的依赖缓存可能已损坏(这有时会在网络连接超时后发生。)重新下载依赖项并同步项目(需要网络)
  • The state of a Gradle build process (daemon) may be corrupt. Gradle构建过程(守护程序)的状态可能已损坏。 Stopping all Gradle daemons may solve this problem. 停止所有Gradle守护进程可以解决此问题。 Stop Gradle build processes (requires restart) 停止Gradle构建过程(需要重启)
  • 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. 您的项目可能正在使用第三方插件,该插件与项目中的其他插件或项目请求的Gradle版本不兼容。
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes. 在损坏的Gradle进程的情况下,您还可以尝试关闭IDE,然后终止所有Java进程。


None of the proposed solutions worked. 所提出的解决方案都没有奏效。 I also tried invalidating caches and manually deleting Gradle caches to force redownload of dependencies and wrapper. 我还尝试使缓存无效并手动删除Gradle缓存以强制重新下载依赖项和包装器。

EDIT: "Upgrading to the latest build tools and Gradle version" is not a solution because this issue still exists. 编辑: “升级到最新的构建工具和Gradle版本” 不是一个解决方案,因为这个问题仍然存在。 And the current workaround to that issue is to disable test coverage "temporarily." 问题的当前解决方法是“暂时”禁用测试覆盖率。 As that issue was originally reported 6 months ago (and despite it's being triaged as "critical"), the workaround is not only bad, but not temporary. 由于该问题最初是在6个月前报告的(尽管它被分类为“关键”),但解决方法不仅是坏的,而且不是暂时的。

The problem seems to be solved for me. 这个问题似乎已经解决了。 This is what I did, including my conjecture as to why it worked. 这就是我所做的,包括我猜测它为何起作用。

  1. I 'upgraded' my project's Android Gradle Build Tools from 2.1.2 to 2.3.0 ( 'com.android.tools.build:gradle:2.3.0' ) 我将'我的项目的Android Gradle Build Tools从2.1.2升级到2.3.0( 'com.android.tools.build:gradle:2.3.0'
  2. I upgraded my Gradle wrapper from 2.14 to 3.3 我将Gradle包装器从2.14升级到3.3
  3. I upgraded my buildToolsVersion from 23.0.3 to 25.0.0. 我将buildToolsVersion从23.0.3升级到25.0.0。

Having done that, Android Studio finally condescended to sync my project. 完成后,Android Studio终于屈服于同步我的项目。 HOWEVER, when I actually attempted to build the project, I ran into this well known bug . 但是,当我真正尝试构建项目时,我遇到了这个众所周知的bug I refuse to 'workaround' this bug, because disabling test coverage is a non-starter. 我拒绝“解决”这个错误,因为禁用测试覆盖是一个非首发。

Having confirmed that bug still holds in the latest build tools, I undid my changes and let AS sync my project again. 确认错误仍然存​​在于最新的构建工具中,我解除了我的更改并让AS再次同步我的项目。 Voilà, it worked. Voilà,它奏效了。

I speculate that it worked this time because changing the build tools twice forced some filesystem changes that I missed when I simply deleted some directories in my ~/.gradle/caches/ and ~/.gradle/daemon/ directories. 推测这次工作有效,因为更改构建工具两次强制了一些文件系统更改,当我只删除~/.gradle/caches/~/.gradle/daemon/目录中的某些目录时,我错过了这些更改。

If I sound at all snarky in this, I apologize, but it's incredibly frustrating for the Android Studio team to release a 'stable' version of their IDE that has undocumented, (near?) breaking changes. 如果我在这听起来很讽刺,我道歉,但Android Studio团队发布他们的IDE的“稳定”版本是非常令人沮丧的,这个版本没有文档记录,(接近?)破坏性更改。 For them to attempt to force an 'upgrade' to a build tool that has a known critical defect (oh, but it's only testing, and who cares about that?) is just wrong. 他们试图强制“升级”到具有已知严重缺陷的构建工具(哦,但它只是测试,谁在乎呢?)是错的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM