gradle task简单使用方法

2019-04-18  本文已影响0人  偷的浮生整日闲

gradle命令

语法:gradle task名称
gradle build:执行build任务
gradle -m build:打印执行build任务之前的前序任务顺序
gradle build -info:执行build任务,并打印详细的编译信息


gradle task

/**
**将lib下的app重命名为app.apk并拷贝至build/outputs/apk/release/目录下(打包后文件替换,嘘!)
**/
task CopyAPK(type: Copy){ //task名称是CopyAPK,类型是copy类型(类似继承),
    from 'libs/app' 
    rename 'app', "app.apk"
    into 'build/outputs/apk/release/'
}
/**
**删除build/outputs/apk/release/app-release.apk,并依赖CopyAPK任务(在执行完CopyAPK之后再执行DeleteAPK)
**/
task DeleteAPK(type: Delete){
    dependsOn CopyAPK
    delete 'build/outputs/apk/release/app-release.apk'
}

gradle安卓任务依赖

project.tasks.whenTaskAdded { theTask ->
if (theTask.name =='assembleRelease') {
assembleRelease.dependsOn DeleteAPK// DeleteAPK之后再执行assembleRelease
    }
}

通过 gradle assembleRelease命令就可以实现,上述task的执行先后顺序(非紧密相连)为:
CopyAPK->DeleteAPK->assembleRelease

上一篇下一篇

猜你喜欢

热点阅读