1. 程式人生 > >Gradle3.0_常用命令和task

Gradle3.0_常用命令和task

Gradle3.0在Android開發中常用命令

  • 生成release的aar
gradlew assembleRelease
  • 生成APK
gradlew build

Gradle3.0在Android開發中常用task

  • 將生成的jar包拷貝到指定目錄並重命名
task makeJar(type: Jar) {
    from zipTree(file('build/intermediates/bundles/release/classes.jar')) // jar包原始檔
    from fileTree(dir: 'src/main'
, includes: ['assets']) baseName = 'permission' // jar包重新命名 destinationDir = file('../package/permission') // 指定複製路徑 exclude('android/', 'BuildConfig.class', 'R.class') exclude { it.name.startsWith('R$'); } } makeJar.dependsOn(build) // 執行gradle命令 // 先rebuild專案,會生成jar包 // gradlew makeJar 再拷貝jar包
  • 將生成的aar拷貝到指定目錄並重命名
task copyAAR(type: Copy) {
    from 'build/outputs/aar/PermissionLib-release.aar'
    into '../package/permission'
    rename { String fileName ->
        fileName = "permission.aar"
    }
}
// 執行gradle命令
// gradlew assembleRelease 先生成aar
// gradlew copyAAR 再拷貝aar