[英]Run task after packageApplication when using the android gradle plugin
Gradle has the ability to run tasks after other tasks. Gradle具有在其他任务之后运行任务的能力。 The syntax is taskY.mustRunAfter taskX .
语法是taskY.mustRunAfter taskX 。 The android gradle plugin says one of the ApplicationVariant tasks it defines is packageApplication .
android gradle插件说它定义的ApplicationVariant任务之一是packageApplication 。
In my build.gradle I have taskX.mustRunAfter packageApplication
在我的build.gradle中,我有
taskX.mustRunAfter packageApplication
The error I get is "Could not find property 'packageApplication' on project ':someproject'." 我得到的错误是“无法在项目中找到属性'packageApplication':someproject'。”
Is it even possible to get access to the packageApplication task? 甚至可以访问packageApplication任务吗? If so is it considered bad practice?
如果这样被认为是不好的做法?
I found my the answer. 我找到了答案。 rciovati cleared up the confusion around mustRunAfter and that what I was doing was the wrong approach.
rciovati清除了围绕mustRunAfter的混乱,我正在做的是错误的做法。 I ended up converted taskY to a groovy function.
我最终将taskY转换为groovy函数。 Then used the following code:
然后使用以下代码:
android.applicationVariants.all { variant ->
// rename apk after we assemble the application
variant.assemble.doLast {
taskY(variant)
}
Please note this sentence from the documentation: 请注意文档中的这句话:
By using 'must run after" ordering rule you can specify that taskB must always run after taskA, whenever both taskA and taskB are scheduled for execution .
通过使用“必须运行后”排序规则,您可以指定taskB必须始终在taskA之后运行, 只要taskA和taskB都被安排执行 。
This means that 这意味着
taskX.mustRunAfter packageApplication
doesn't make the taskX
run always after packageApplication
but just if you type: 在
packageApplication
之后不会使taskX
始终运行,但只要键入:
./gradlew taskX packageApplication
On the other hand, it doesn't define a dependency, that is it doesn't automatically run taskX
task. 另一方面,它没有定义依赖关系,也就是说它不会自动运行
taskX
任务。
To do something, after a task is executed you can use the doLast
closure: 要执行某些操作,执行任务后您可以使用
doLast
闭包:
taskX.doLast{ println 'Hello' }
The packageApplication
is a property of the ApplicationVariant
class but not a task. packageApplication
是ApplicationVariant
类的属性,但不是任务。 The tasks are package<VariantName>
. 任务是
package<VariantName>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.