简体   繁体   English

Android + Gradle:将任务注入构建

[英]Android + gradle: injecting a task into build

I have a custom script which runs on the source (.java) and AndroidManifest.xml. 我有一个在源(.java)和AndroidManifest.xml上运行的自定义脚本。 I'd like to execute this script as part of the gradle build process at the start of the assembleRelease task (maybe just after app:preBuild). 我想在assembleRelease任务开始时(可能只是在app:preBuild之后)执行此脚本,作为gradle构建过程的一部分。

Any idea of how I can go about doing this? 关于我该如何做的任何想法?

I know I can do something like this to exec the script: 我知道我可以做这样的事情来执行脚本:

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

But I'm not sure where to put that, etc... 但我不确定该放在哪里,等等。

You can add a custom action to assembleRelease with doFirst method: 您可以使用doFirst方法向assembleRelease添加自定义操作:

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

or define dependency: 或定义依赖项:

assembleRelease.dependsOn DoStuff
assembleRelease.mustRunAfter DoStuff //this might be redundant

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM