通过Gradle动态配置minSdkVersion加快编译速度

2020-04-01  本文已影响0人  小楠总

今天在查看官方文档关于加快构建速度方面的建议,https://developer.android.com/studio/build/optimize-your-build?hl=zh-cn,里面提到:

官方文档
/**
 * 修改本地文件local.properties中的APP_LOCAL_DEBUG以控制是否为LocalDebug
 * @return
 */
def isLocalDebug() {
    def isLocalDebug = false
    def file = rootProject.file('local.properties')
    if (file.exists() && file.isFile()) {
        Properties properties = new Properties()
        properties.load(file.newDataInputStream())
        isLocalDebug = Boolean.parseBoolean(properties.getProperty('APP_LOCAL_DEBUG', 'false'))
    }
    println('isLocalDebug: ' + isLocalDebug)
    return isLocalDebug
}
minSdkVersion build_versions.app_local_debug ? 21 : build_versions.min_sdk

最后,在local.properties中添加APP_LOCAL_DEBUG=true就可以了,编译时间从原来的40秒直接优化到20秒,效果杠杠滴,而且电脑的内存占用也大大降低了,有兴趣可以尝试一下。

上一篇 下一篇

猜你喜欢

热点阅读