如何减少带薪编译时间
引言
做Android开发的大兄弟肯定都知道Android Studio编译使用的是Gradle,项目大起来,Gradle编译花个5min~10min是常有的事情,一天编译调试10次是常有的事情,也就被大家常说的带薪编译!!!
实操
ps:以下这些配置都是编写在项目根目录下的:gradle.properties文件当中。
### 减少Gradle的启动时间
1 | org.gradle.daemon=true |
这样做的目的是减少每次启动Gradle的启动。官方原话如下:
When set to true the Gradle Daemon is used to run the build. Default is true.
启用并行构建
1 | org.gradle.parallel=true |
当项目中有多个模块时,而且模块之间无耦合时,可以启用并行编译。官方原话如下:
Parallel builds require projects to be decoupled at execution time, i.e. tasks in different projects must not modify shared state. Read more about that topic in the User Manual before using –parallel extensively. Also be aware that Gradle versions before 4.0 could run clean and build tasks in parallel, resulting in failures. On these older versions it is best to call clean separately.
效果,可以参看这个链接
### 启用按需编译
1 | org.gradle.configureondemand=true |
项目中可能存在很多模块,可能部分模块是本次编译时不需要的,那么配置此项可以不对那些不需要的modle进行编译,从而减少编译时间,官方原话如下:
Enables incubating configuration on demand, where Gradle will attempt to configure only necessary projects.
更多关于Gradle配置项的说明,点击此处
欢迎大家,一起来探讨技术!!!