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)
  }
}

You may find some inspiration here:
https://www.reddit.com/r/androiddev/comments/3ig3gm/show_us_your_gradle_tasks/

HTH,

Michal

On Wed, Aug 26, 2015 at 7:17 PM Vaibhav Vishal <[email protected]> wrote:

> 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 ?
>
> On Wednesday, 26 August 2015 20:52:50 UTC+5:30, Michal Bendowski wrote:
>>
>> Do you create one instance of you task per variant? If not, it will run
>> only once.
>>
>> Michal
>>
>> On Sunday, August 23, 2015 at 7:59:46 PM UTC+1, Vaibhav Vishal wrote:
>>>
>>> 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 ?
>>>
>>>
>> --
> 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
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to