简体   繁体   English

Gradle项目同步失败(Android Studio)

[英]Gradle project sync failed (Android Studio)

I have an error everytime I switch from one branch to another in my project (so I have to do 'Invalidate cache and restart', it helps, but takes time and it's not normal to do it everytime): 每次从项目中的一个分支切换到另一个分支时,我都会出错(因此,我必须执行“使缓存无效并重新启动”,这虽然有帮助,但要花一些时间,而且每次都这样做是不正常的):

Gradle project sync failed. Gradle项目同步失败。 Basic functionality will not work properly. 基本功能将无法正常运行。

It started after I updated gradle and Android Studio. 它是在我更新gradle和Android Studio之后开始的。 Now in my 'Project Structure' -> 'Project' I have Gradle version 3.3 and Android Plugin Version 2.3.0. 现在在“项目结构”->“项目”中,我有Gradle版本3.3和Android插件版本2.3.0。 The same is in other my branch. 我的其他分支也一样。 Any advice what is wrong? 有什么建议有什么不对吗?

Make sure that both run in the same versions and try again. 确保两者都在相同版本中运行,然后重试。 Try these two tasks: 尝试以下两个任务:

  1. 1)Go to File>>Other Settings>>Default Porject Structure. 1)转到文件>>其他设置>>默认对象结构。 Check there the jdk path. 检查那里的JDK路径。 Make sure that you have 64_bit.Finally, after this clean project and rebuild it. 确保您拥有64_bit。最后,在这个干净的项目之后,重新构建它。

    2.Go to the directory \\Users\\user.gradle\\caches\\2.x. 2.转到目录\\ Users \\ user.gradle \\ caches \\ 2.x。 You will find the directories scripts & scripts-remapped. 您将找到目录scripts&scripts-remapped。 Keep a backup of them and then delete them from the directory.Retry gradle sync. 备份它们,然后从目录中删除它们。重试gradle同步。 It should work as it will generated new cache files 它应该工作,因为它将生成新的缓存文件

Found the solution: just click Tools > Android > Sync Project with Gradle Files (did it in every branch). 找到了解决方案:只需单击工具> Android>用Gradle文件同步项目(在每个分支中进行了设置)。 Everything is fine now. 现在一切都很好。 Thanks to this article: http://devdeeds.com/update-gradle-plugin-android-studio/ 感谢本文: http : //devdeeds.com/update-gradle-plugin-android-studio/

My solution is : 我的解决方案是:

  1. File -> Invalidate caches / Restart 文件->使缓存无效/重新启动
  2. Shutdown Android Studio 关闭Android Studio
  3. Rename/remove .gradle folder in the user home directory 重命名/删除用户主目录中的.gradle文件夹
  4. Now try to import that project using another project 现在尝试使用另一个项目导入该项目
  5. Gradle build success !! 摇篮建立成功! Done. 完成。

Hope it helps. 希望能帮助到你。

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

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