较长的构建时光将会减缓项目标开辟进度,特别是对于大年夜型的项目,app的构建时光长则十几分钟,短则几分钟,长的构建时光已经成了开辟瓶颈,本篇文┞仿根据Google官方文档,加上本身的一些懂得供给一些晋升app构建速度的优化建议。
1. 为开辟情况创建一个变体
有很多设备是你在预备app的release 版本的时刻须要,然则当你开辟app的时刻是不须要的,开启不须要的构建过程会使你的增量构建或者clean构建变得很慢,是以须要构建一个只保存开辟时须要设备的变体,如下例子创建了一个dev和prod变体(prod 为release 版本的设备)。
- android {
- ...
- defaultConfig {...}
- buildTypes {...}
- productFlavors {
- // When building a variant that uses this flavor, the following configurations
- // override those in the defaultConfig block.
- dev {
- // To avoid using legacy multidex, set minSdkVersion to 21 or higher.
- minSdkVersion 21
- versionNameSuffix "-dev"
- applicationIdSuffix '.dev'
- }
- prod {
- // If you've configured the defaultConfig block for the release version of
- // your app, you can leave this block empty and Gradle uses configurations in
- // the defaultConfig block instead. You still need to create this flavor.
- // Otherwise, all variants use the "dev" flavor configurations.
- }
- }
- }
2 . 避免编译不须要的资本
避免编译和包含你没有测试的资本(比如添加的一个本地的说话和屏幕密度资本),你可以只在你的’dev’ flavor下指定一种说话和一个屏幕密度,如下:
- android {
- ...
- productFlavors {
- dev {
- ...
- // The following configuration limits the "dev" flavor to using
- // English stringresources and xxhdpi screen-density resources.
- resConfigs "en", "xxhdpi"
- }
- ...
- }
- }
膳绫擎的设备将会限制dev 变体只应用 english string 资本和 xxhdpi 屏幕密度资本。
3 . 设备debug 构建的Crushlytics为弗采取状况
在debug 构建状况下,如不雅你不须要运行崩溃上报,你可以将这个插件设置为弗采取状况来晋升你的构建速度,如下: