简体   繁体   English

Android Studio:Gradle Build运行3分钟

[英]Android Studio: Gradle Build Running for 3 minutes

I have a simple app and every time I hit "run" it takes more than 3 minutes for gradle to finish build and load the app. 我有一个简单的应用程序,每当我点击“运行”时,gradle都需要3分钟以上的时间来完成构建和加载应用程序。 And it happens on both emulator and my android phone. 它发生在模拟器和我的Android手机上。 And before you mark this post as a similar post, hear me out: I have been tying to troubleshoot the issue since last 10 days. 在您将此帖子标记为类似帖子之前,请听我说:自最近10天以来,我一直在努力解决问题。 I have gone through more than 20 stack overflow similar questions (like this one) and dozens of articles on google and I've tried every solution they suggested but nothing seems to work. 我已经经历了20多个关于类似问题的堆栈溢出问题(例如这个问题),并且在Google上发表了数十篇文章,我已经尝试了他们提出的每种解决方案,但似乎没有任何效果。 Here is what I've tried so far: 到目前为止,这是我尝试过的:

  • Added org.gradle.parallel=true and org.gradle.daemon=true to gradle.properties 向gradle.properties添加了org.gradle.parallel=trueorg.gradle.daemon=true
  • Added --parallel and --offline to command line option settings 在命令行选项设置中添加了--parallel和--offline
  • Enabled "offline work" in settings 在设置中启用了“离线工作”
  • Enabled/Disabled "instant run" - didn't make any difference 启用/禁用“即时运行”-没什么区别
  • I've allocated a lot of memory: org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF- 8 我分配了很多内存: org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF- 8
  • I've completely disabled Windows Defender 我已经完全禁用Windows Defender
  • I am using latest version of gradle (2.10) and latest version of Android Studio which is 2.1.1 Even after trying all these, it still takes more than 3 minutes and it is getting very frustrated. 我正在使用gradle(2.10)的最新版本和2.1.1的Android Studio的最新版本。即使尝试了所有这些,它仍然需要3分钟多的时间,并且感到非常沮丧。

When app is running for several minutes, I've noticed :app:processDebugResources in gradle console. 当应用程序运行几分钟后,我注意到gradle控制台中的:app:processDebugResources So maybe this might be causing the slow down, I don't know. 因此,也许这可能会导致速度下降,我不知道。 Also, I have an xml file that I am parsing and that xml file has about 70,000 lines in it. 另外,我有一个要解析的xml文件,并且该xml文件中包含大约70,000行。 Could this be causing any problem? 这会引起任何问题吗? Could it be Windows 8? 可能是Windows 8吗?

Please provide any suggestions on how to fix this. 请提供有关如何解决此问题的任何建议。 Thank you :) 谢谢 :)

I have found out why this was happening. 我发现了为什么会这样。 It was because I was parsing the XML in the onCreate function() and since the XML had 70,000 lines, the compiler was taking long time. 这是因为我在onCreate function()中解析XML,并且由于XML有70,000行,所以编译器要花费很长时间。 But after moving the file to "assets" folder, the problem has solved. 但是将文件移到“资产”文件夹后,问题已解决。 It was my mistake and had nothing to do with gradle settings but if someone stumbles upon a similar issue, I recommend you to try all the things I've listed above and your gradle build should run faster. 这是我的错误,与gradle设置无关,但是如果有人偶然发现了类似的问题,我建议您尝试上面列出的所有操作,并且gradle构建应该运行得更快。

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

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