I have an Android project with multiple modules where the build time is slow even if I try to rebuild it without changing anything.
Its structure is similar to:
There are more "parent" (and independent parent siblings) and "feature" modules but the setup is that of the picture.
My gradle.properties
file is as follows:
org.gradle.jvmargs=-Xmx4096m -Xms2048m
org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configureondemand=true
And I'm using the Gradle version 3.5 and the plugin version 2.4.0-alpha7.
The project also uses multidex (javaMaxHeapSize "4g"
and jumboMode true
), data binding, kotlin alongside java, and several annotation processors.
When a build, I can see multiple threads running different tasks in parallel for most of the project, except mostly for the final "app" module (which I assume is normal).
But a lot of time seems to be spent on different ::compileJavaWithJavac tasks. Even without changing anything, build takes about 30 secs on a MacBook Pro i7 with 16 Gb RAM.
If I change one line of code inside a method of a feature module (without even changing the method's signature), the build time goes over 1:30 minutes.
Are these normal times? Is there something I can optimise further to improve build times?
I also checked some of the other answers:
- From this one, setting
preDexLibraries = false
doesn't help and I already useassembleDebug
incremental = true
suggested here doesn't work and is deprecated- Disabling instant run seems to help a little but not much
- The project's build flavour discussed above already sets
minSdkVersion 21