Android + gradle:将任务注入构建

时间:2014-10-23 09:01:30

标签: android gradle android-studio android-gradle

我有一个在源(.java)和AndroidManifest.xml上运行的自定义脚本。 我想在assembleRelease任务开始时执行这个脚本作为gradle构建过程的一部分(可能就在app:preBuild之后)。

我知道如何做到这一点?

我知道我可以做这样的事来执行剧本:

task DoStuff(type:Exec) {
    workingDir 'path/to/script'
    commandLine 'python3', 'do_stuff.py'
} 

但我不知道该放哪个等等......

1 个答案:

答案 0 :(得分:0)

您可以使用assembleRelease方法向doFirst添加自定义操作:

assembleRelease.doFirst {
   //invoke python script but there's no access to `workingDir` or `commandLine` 
   //because it's an action not a task
}

或定义依赖:

assembleRelease.dependsOn DoStuff
assembleRelease.mustRunAfter DoStuff //this might be redundant
相关问题