使用 build cache加速android编译

2,522 阅读1分钟

##使用 build cache

Android plugin 2.3.0+ 可以用

build.gradle满足如下配置时可以使用

android {
  defaultConfig {
    // If you do enable multidex, you must also set
    // minSdkVersion to 21 or higher.
    multiDexEnabled false
  }
  buildTypes {
    <build-type> {
      minifyEnabled false
    }
  }
  dexOptions {
    preDexLibraries true
  }
  ...
}
...

默认位置为:<user-home>/.android/build-cache/,修改目录的配置方法,在gradle.properties中添加配置

// You can specify either an absolute path or a path relative
// to the gradle.properties file.
android.buildCacheDir=<path-to-directory>

生效方法,点studio中的 Sync Project

清除缓存命令

gradlew cleanBuildCache

关闭方法,在gradle.properties中添加配置

// To re-enable the build cache, either delete the following
// line or set the property to 'true'.
android.enableBuildCache=false

生效方法,点studio中的 Sync Project

参考链接:developer.android.com/studio/buil…