Building gradle takes so long (8 minutes to 20 min

2019-06-01 05:24发布

Is it normal that building Gradle of my android project takes at least 8 minutes and something goes up to 20 minutes?

I am running on Windows 10 with 8 Gb RAM, 1.7 Ghz Intel core i3 processor.

If not, kindly advice how to speed up the building time.

3条回答
何必那么认真
2楼-- · 2019-06-01 05:38

Following the steps will make it 10 times faster and reduce build time 90%

First create a file named gradle.properties in the following directory:

/home/<username>/.gradle/ (Linux)
/Users/<username>/.gradle/ (Mac)
C:\Users\<username>\.gradle (Windows)

Add this line to the file:

org.gradle.daemon=true

org.gradle.parallel=true
查看更多
Melony?
3楼-- · 2019-06-01 05:59
    You can add following code in gradle.properties . this file will be under your project folder.



     org.gradle.daemon=true
     org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
     org.gradle.parallel=true
     org.gradle.configureondemand=true


And add following code in you app build.gradle file

lintOptions {
        disable 'InvalidPackage'
    }
    dexOptions {
        incremental true
        maxProcessCount 4
        javaMaxHeapSize "4g"
    }
    tasks.whenTaskAdded { task ->
        if (task.name.equals("lint")) {
            task.enabled = false
        }
查看更多
狗以群分
4楼-- · 2019-06-01 06:01

Delete the files in build/android-profile

(It contains .rawproto and .json files)

After doing this you may see monstrous speed increases. One of the reasons for the slowdown may be Lint checking these files during the build. The folder had grown to 2GB on my computer and contained over 7000 files. That can't be good. I guess an alternative approach could be to configure Lint to ignore this folder, but I haven't investigated any further.

Warning: I am not completely sure whether these files have any value, so you can check for yourself. You definitely don't need them in order to build the project, that's for sure (you don't check them in GIT anyway).

查看更多
登录 后发表回答