Android Studio slow incremental build

蹲街弑〆低调 提交于 2020-01-03 18:41:23

问题


I have gone through many steps to refine our build system (those and more). Later, I read this official blogpost that claims that build times are improved 5-10x with incremental builds in Gradle 3.4. Indeed, our incremental builds were not working, because we used annotationProcessors. Since Gradle 4.7 annotationProcessors can opt-in to be compatible with incremental builds. I have gone through many dependency updates to activate incremental builds with annotationProcessors that support it.

Through various configurations and improvements I was able to reduce our build time (prebuilt) from ~30s to ~19s. Based on the incremental build blogpost I was assuming that I could further reduce build times to ~5s.

Unfortunately, with incremental builds it only came down to ~15s. Using --profile and --info I tried to further diagnose the issue. Only exctracting the gradle task compileDevDebugJavaWithJavac it shows that the compilation step went from ~16s to ~12s.

Incremental compilation of 476 classes completed in 12.51 secs.

It appears to me that this is too slow for a single line change, and it doesn't nearly reflect what Gradle claims for incremental builds. I specifically tried to change files with few dependencies and I know that public constants trigger full rebuilds. What else can cause an incremental build for only a single file to be that slow?

I also tried to enable the experimental feature

android.enableSeparateAnnotationProcessing=true

which does work and splits up my build into two compile steps

compileDevDebugJavaWithJavac 6.777s

processDevDebugAnnotationsWithJavac 6.104s

I was hoping that in conjunction with

org.gradle.parallel=true

Both tasks might run in parallel and almost half the build time. But apparently parallel processing does not work here, or does it?

What else can be done to increase build times of very small changes?

Edit: I found out that the main problem is that we have too many class dependencies and it always triggers the compilation of 476 classes (see this question). As I don't expect to resolve enough class dependencies in our legacy code: my question still stands. Can the project can enableSeparateAnnotationProcessing be parallelized or is there any other configuration?


回答1:


Rather than worrying about the incremental aspect, maybe there are optimizations you can make to speed up development builds. Are you using proguard? If so, disable it for your development/staging builds and only use it for release builds.

If you're already doing that- i'm not sure what to suggest short of bumping up machine specs.



来源:https://stackoverflow.com/questions/54585625/android-studio-slow-incremental-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!