Why does assembleDebug takes much longer then project build and how to optimize it?

青春壹個敷衍的年華 提交于 2021-02-06 19:31:36

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/34811043/why-does-assembledebug-takes-much-longer-then-project-build-and-how-to-optimize

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