为什么assembleDebug比项目构建需要更长的时间以及如何优化它?

Ole*_*nov 8 android gradle android-studio

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

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

15:13:43 Executing tasks: [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:compileDebugSources, :app:compileDebugAndroidTestSources]
15:13:54 Gradle build finished in 11s 596ms
Run Code Online (Sandbox Code Playgroud)

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

15:15:09 Executing tasks: [:app:assembleDebug]
15:15:58 Gradle build finished in 49s 676ms
Run Code Online (Sandbox Code Playgroud)

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

Ole*_*nov 9

为什么:

最近我在我的应用程序中启用了multidex,因为我有超过65k的方法.德兴需要花费大量时间才能完成.

如何加快构建:

转到设置(ctrl + alt + s) - > 构建,执行,部署 - > 编译器

并行启用编译模块并在编译器中添加"--offline"会将执行时间减少到大约15秒.

在此输入图像描述

  • 如何在Visual Studio Code中做到这一点? (2认同)