简体   繁体   中英

Run task after packageApplication when using the android gradle plugin

Gradle has the ability to run tasks after other tasks. The syntax is taskY.mustRunAfter taskX . The android gradle plugin says one of the ApplicationVariant tasks it defines is packageApplication .

In my build.gradle I have taskX.mustRunAfter packageApplication

The error I get is "Could not find property 'packageApplication' on project ':someproject'."

Is it even possible to get access to the packageApplication task? 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. I ended up converted taskY to a groovy function. 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 .

This means that

taskX.mustRunAfter packageApplication

doesn't make the taskX run always after packageApplication but just if you type:

./gradlew taskX packageApplication

On the other hand, it doesn't define a dependency, that is it doesn't automatically run taskX task.

To do something, after a task is executed you can use the doLast closure:

taskX.doLast{ println 'Hello' }

The packageApplication is a property of the ApplicationVariant class but not a task. The tasks are package<VariantName> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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