13

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:

Simplified project setup

There are more "parent" (and independent parent siblings) and "feature" modules but the setup is that of the picture.

My gradle.propertiesfile 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 use assembleDebug
  • 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
ADev
  • 5,259
  • 2
  • 16
  • 29
  • 1
    Do you finally found the culprit for long build times? I've encountered similar problem. – Fadli Oct 16 '17 at 16:09
  • This is really eating the productive time google should release clear documentation the approach when there are multiple module in Android application & how to increase the speed – Abhijit Chakra Jun 02 '21 at 04:29

1 Answers1

0

you should make the feature module independent as much you can and any dependency with other module please consider the stub. A kind of the proxy which contain only interface feature1 -> featureonestub->feature2

Bytecode
  • 6,551
  • 16
  • 54
  • 101
  • What do you mean by "any dependency with other module please consider the stub"? – Al.G. Feb 20 '23 at 07:29
  • use interface module resolve the compile time dependency and use dagger or any DI frameworks to provide runtime implementation – Bytecode Mar 25 '23 at 06:23