为什么 assembleDebug 比项目构建需要更长的时间以及如何优化它? [英] Why does assembleDebug takes much longer then project build and how to optimize it?

查看:19
本文介绍了为什么 assembleDebug 比项目构建需要更长的时间以及如何优化它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在处理 Android Studio 中的 gradle 构建时间.通过删除一些依赖项,我设法将构建时间从大约 3 分钟减少到 10 秒,但事情是这样的:

当我重建项目时,大约需要 10 秒:

15:13:43 执行任务:[clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugAndroidTestSources]15:13:54 Gradle 构建在 11 秒 596 毫秒内完成

但是,当我启动应用程序时,它需要更长的时间,大约一分钟:

15:15:09 执行任务:[:app:assembleDebug]15:15:58 Gradle 构建在 49 秒 676 毫秒内完成

造成如此大差异的原因是什么?这是否仍然是因为大量的 gradle 依赖或其他原因?我可以以某种方式减少构建时间吗?

解决方案

为什么:

最近我在我的应用程序中启用了

I've been dealing with gradle build time in Android Studio recently. I've managed to decrease the build time from about 3 mins to 10 seconds by removing some dependencies, but here's the thing:

When I rebuild project it takes about 10 seconds:

15:13:43 Executing tasks: [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugAndroidTestSources]
15:13:54 Gradle build finished in 11s 596ms

However when I launch the app, it takes a lot longer, about a minute:

15:15:09 Executing tasks: [:app:assembleDebug]
15:15:58 Gradle build finished in 49s 676ms

What is the cause of such big difference? Is this still because of the large amount of gradle dependencies or something else? Can I reduce the build time somehow?

解决方案

Why:

Recently I enabled multidex in my app because I had over 65k methods. Dexing is what was taking a lot of time to complete.

How to speed up build:

Go to Settings (Ctrl + alt + s) -> Build, Execution, Deployment -> Compiler

Enabling compiling modules in parallel and adding --offline in compiler has decreased my execution time to about 15 seconds.

这篇关于为什么 assembleDebug 比项目构建需要更长的时间以及如何优化它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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