16

So I have been working on a simple app in Android Studio and since last couple of days, whenever I click "Run", it takes more than 5 minutes to build. It didn't used to be this slow. I don't know why. It says "Gradle Build Running" and then app is loaded after 5 minutes. And this happens on both the emulator and on my android device. My grade version is 2.10 I looked up this issue and I have tried everything that other similar posts have suggested including:

  • Adding --parallel and --offline to command line option settings
  • Enabling 'offline work' in Gradle setting
  • Adding org.gradle.daemon=true in gradle.properites file

Below are the screen shots.

image 1

image 2

image 3

Even after doing all these, my grade build takes 5+ minutes. This is what was there in the event log:

10:27:57 AM Executing tasks: [:app:clean, :app:generateDebugSources,     :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies,  :app:generateDebugAndroidTestSources, :app:assembleDebug]
10:34:24 AM Gradle build finished in 6m 26s 378ms

Any suggestions will be helpful. Thanks in advance :)

Chad Bingham
  • 32,650
  • 19
  • 86
  • 115
Parth Bhoiwala
  • 1,282
  • 3
  • 19
  • 44

3 Answers3

19

Enable "Dex In Process" for faster app builds (for Android Studio 2.1).

increase the amount of memory allocated to the Gradle Daemon VM by 1 Gb, to a minimum of 2 Gb, using the org.gradle.jvmargs property:

org.gradle.jvmargs=-Xmx2048m

Read about it here: Faster Android Studio Builds with Dex In Process

dexinprocess

jayeshsolanki93
  • 2,096
  • 1
  • 20
  • 37
  • 1
    I already have that line of code in my gradle.properties folder: it looks like this "org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8" – Parth Bhoiwala May 16 '16 at 15:08
  • Yes, but that line is commented by default. Add `org.gradle.jvmargs=-Xmx2048m` below it. I tried it in a project of mine, build time significantly decreased. It reduced from 17 seconds to 8 seconds. – jayeshsolanki93 May 16 '16 at 17:07
  • I am having the same issue and I tried adding that line, no luck :( –  May 18 '16 at 15:37
  • 1
    I added the line "org.gradle.jvmargs=-Xmx2048m" but it doesn't seem to have any effect. It still takes 5+ mins to build. – Parth Bhoiwala May 18 '16 at 15:39
  • where i added org.gradle.jvmargs=-Xmx2048m in gradle.properties – Amey Bawiskar Feb 11 '17 at 11:52
  • 1
    Worked a treat - thanks! I also followed the advice here and used the Offline Setting and additional arguments in the gradle.properties file - this took my build from over 8 minutes to around 4 seconds. https://stackoverflow.com/questions/29391421/android-studio-gradle-takes-too-long-to-build – vinnyh Dec 11 '18 at 17:22
12

Other solutions here have not helped me yet. I am seeing builds lasting 30+ minutes only to end with Error:Out of memory: GC overhead limit exceeded. But I have made slight progress the past few days.

Note: I do not believe this is a solution to the problem, just a workaround until Jack works out the kinks

I added the following to my build gradle:

android {
    ....
  defaultConfig {
    ....
    jackOptions {
            enabled true
            additionalParameters('jack.incremental': 'true')
        }
    }

    compileOptions {
        incremental true
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dexOptions {
        javaMaxHeapSize '4096m'
    }

}

For some reason, adding

org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 

to my gradle.properties made no difference. I had to add it in the dexOptions.

Chad Bingham
  • 32,650
  • 19
  • 86
  • 115
0

In gradle.properties you can try using:

org.gradle.jvmargs=-Xmx2048m
org.gradle.caching=true

Hope this helps !!

Partho63
  • 3,117
  • 2
  • 21
  • 39