Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 313
Parth Bhoiwala Avatar asked Jun 03 '16 02:06

Parth Bhoiwala


People also ask

Why is Gradle build taking so long in Android Studio?

Dynamic Dependencies slow down your build since they keep searching for the latest builds every time. To improve the performance we need to fix the version in place. Use only those dependencies that you need. For example google maps dependency, instead of importing compile 'com.

Why does Gradle build take so long?

Check your Internet connection. If internet speed is very slow gradle build will also take long time to build. I check by change my wifi internet connection with another one good speed connection. Now build time is normal.

What does Gradle build running mean?

Gradle builds are used to define a project and its tasks. At least one Gradle build file is located in the root folder of the project. A task represents the work that a Gradle build has to perform, e.g., compiling the source code of the program. You can execute multiple tasks at a time under one build file.


1 Answers

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.

like image 59
Parth Bhoiwala Avatar answered Oct 21 '22 16:10

Parth Bhoiwala