Android Studio缓慢的增量构建 [英] Android Studio slow incremental build

查看:266
本文介绍了Android Studio缓慢的增量构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经经历了许多步骤来完善我们的构建系统(官方博客,该文章声称构建时间可以提高5到10倍Gradle 3.4中的增量构建.确实,我们的增量构建无法正常工作,因为我们使用了注解处理器.由于Gradle 4.7注解处理器可以选择加入与之兼容增量构建.我已经进行了许多依赖更新,以使用支持它的annotationProcessor来激活增量构建../p>

通过各种配置和改进,我能够将构建时间(预构建)从〜30s减少到〜19s.基于增量构建博客文章,我假设我可以将构建时间进一步减少到〜 5秒.

不幸的是,随着增量构建,它仅下降到约15秒.我尝试使用--profile--info进一步诊断问题.仅吸引了gradle任务compileDevDebugJavaWithJavac,它表明编译步骤从〜16s变为〜12s.

在12.51秒内完成476个类的增量编译.

在我看来,这对于单行更改来说太慢了,并且它几乎不能反映Gradle对于增量构建的要求.我专门尝试更改几乎没有依赖关系的文件,而且我知道公共常量会触发完全重建.还有什么会导致仅单个文件的增量构建速度如此之慢?

我还尝试启用实验功能

android.enableSeparateAnnotationProcessing=true

可以正常工作,并将我的构建分为两个编译步骤

compileDevDebugJavaWithJavac 6.777s

processDevDebugAnnotationsWithJavac 6.104s

我希望能与

一起

org.gradle.parallel=true

这两个任务可能并行运行,并且构建时间将近一半.但是显然并行处理在这里行不通吗?

还能做些什么来增加非常小的更改的构建时间?

我发现主要的问题是我们有太多的类依赖关系,并且总是触发476个类的编译(请参阅解决方案

也许不用担心增量方面的问题,也许可以进行一些优化来加快开发速度.您在使用proguard吗?如果是这样,请在您的开发/暂存版本中禁用它,而仅将其用于发行版本.

如果您已经在做-不知道建议什么以提高机器规格.

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?

解决方案

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.

这篇关于Android Studio缓慢的增量构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆