Execute a custom task for all product flavors

52 views
Skip to first unread message

Vaibhav Vishal

unread,
Aug 23, 2015, 2:59:46 PM8/23/15
to adt-dev
Here is what I am trying to do - 
I have a task which should run before android's `process<flavorName><buildType>Resources` task for which dependency is set as below :

myTask >> {
// use the output of mergeResources task and do something with it before execution of process task
}

tasks.whenTaskAdded { task ->
  //if task name matches `process<flavorName><buildType>Resources`
task.dependsOn myTask
}

This works well in case I have only one flavor. But in case of more than one flavor, this happens only for the last flavor which is added.

I want myTask to execute for all the flavors. How can I achieve this ?
 

Michal Bendowski

unread,
Aug 26, 2015, 11:22:50 AM8/26/15
to adt-dev
Do you create one instance of you task per variant? If not, it will run only once.

Michal

Vaibhav Vishal

unread,
Aug 26, 2015, 2:17:05 PM8/26/15
to adt-dev
No, I did not create multiple instances of task. There is only one instance as shown in my post above.
How to create more than one instance of a task ?

Michal Bendowski

unread,
Aug 27, 2015, 10:35:10 AM8/27/15
to adt-dev
You will have to do something like this:

android {
  applicationVariants.all { v ->
    def myTask = tasks.create("custom" + v.name) << {
       // do stuff
    }
 
    myTask.dependOn v.assemble
    // or myTask.dependOn tasks.getByName("assemble" + v.name.capitalize)
  }
}


HTH,

Michal

--
You received this message because you are subscribed to a topic in the Google Groups "adt-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adt-dev/L99SK7AXlRk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages