9

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. And it happens on both emulator and my android phone. 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. 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. Here is what I've tried so far:

  • Added org.gradle.parallel=true and org.gradle.daemon=true to gradle.properties
  • Added --parallel and --offline to command line option settings
  • 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
  • I've completely disabled 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.

When app is running for several minutes, I've noticed :app:processDebugResources in gradle console. 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. Could this be causing any problem? Could it be Windows 8?

Please provide any suggestions on how to fix this. Thank you :)

Community
  • 1
  • 1
Parth Bhoiwala
  • 1,282
  • 3
  • 19
  • 44
  • 1
    What are your system configurations? Which Java version and provider are you using? What is your system architecture? – Akash Agarwal Jun 03 '16 at 02:49
  • 1
    +1 for the clear post and research effort. Regarding your 70k liner xml file. Are you parsing in the beginning of the app itself? It might be the reason. – AL. Jun 03 '16 at 02:51
  • And, I'm parsing the XML when user clicks a button not when app loads – Parth Bhoiwala Jun 03 '16 at 02:55
  • What version of android gradle plugin do you have? You can profile gradle build with `--profile` command line option. I suppose the xml file is in `assets` folder – Eugen Martynov Jun 03 '16 at 03:24
  • 2
    Try really latest gradle 2.13 also – Eugen Martynov Jun 03 '16 at 03:24
  • 1
    Run the gradle build with --debug option. It will show you what it is doing exactly. – MartinTeeVarga Jun 03 '16 at 06:27
  • I tried gradle 2.13 but no effect. My xml file is in a folder named 'xml" inside "res" folder. And when I ran the project using --debug option, I noticed that it was stuck on "org.gradle.process.internal.ExecHandleRunner] waiting until streams are handled" for almost 3 minutes. – Parth Bhoiwala Jun 03 '16 at 13:28
  • Try to build a really simple application. Does that take 3 minutes as well? – mehulmpt Jun 08 '16 at 17:29

1 Answers1

1

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. 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.

Parth Bhoiwala
  • 1,282
  • 3
  • 19
  • 44