为什么assembleDebug比项目构建花费更多的时间,以及如何对其进行优化? [英] Why does assembleDebug takes much longer then project build and how to optimize it?

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

问题描述

最近我一直在处理Android Studio中的gradle构建时间.通过消除一些依赖性,我设法将构建时间从大约3分钟减少到10秒,但这就是问题所在:

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

  15:13:43执行任务:[干净,:app:generateDebugSources,:app:generateDebugAndroidTestSources,:app:compileDebugSources,:app:compileDebugAndroidTestSources]15:13:54 Gradle构建完成于11s 596ms 

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

  15:15:09执行任务:[:app:assembleDebug]15:15:58 Gradle构建完成49s 676ms 

造成如此巨大差异的原因是什么?这仍然是由于大量的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天全站免登陆