project with several flavor dimensions (e.g. environment, platform, and brand flavor that has variants A through F)
add brand flavor directory for each brand A through F, with its own flavor.gradle file. Main app gradle file applies each of these so everything can be kept separate
each brand gradle file has a custom task registered that will fetch and store files locally
select variant and build, only fetch and store files for given variant and none of the others
The tasks are written and confirmed to work, but running into an issue where when a variant is chosen and built, it runs the custom gradle task for each variant, not just the selected one
tasks are registered under the productFlavor definition in each gradle file, then each gradle file is applied to the main app gradle
I have tried only registering the custom tasks using applicationVariants.all and looking for the brand flavor to match expected value. This still runs several times and over all variants
I have tried using afterEvaluate and adding a task dependency between the assemble task for that variant and the custom task. Does not work either (Note: I use this afterEvaluate clause to ensure we only copy over the correct google-services.json file for Crashlytics setup and it works well).
Unsure really how to ensure we only have the custom task for the selected variant to run, and none of the others that are defined. Any tips appreciated - thanks
Generally afterEvaluate { ... } is highly discouraged bad practice and the main earnings you get from using it are timing problems, ordering problems, and race conditions, so be very careful when you think you need to use it. Most often it is a sign for not doing something the proper way.
Regarding your actual question, your description - at least for me - is too abstract to draw any conclusion. It could maybe help if you can provide an MCVE.
Thanks for the note on afterEvaluate - agreed it is not the best, it has introduced more warnings in our builds but it yielded the correct result. I will still be looking to improve that.
MCVE, I can provide a folder structure that shows what I am looking at, as well as sample gradle file setups. I have not included the entire contents of gradle files for brevity.
When I select a variant in Android Studio (e.g. devFireTvFlavoraDebug) and build/make so the gradle builds run - it runs the tasks for every flavor A through F, instead of just the task for A. Is there a way to set this up so that it only runs the task for the selected build variant?
I’m not really into Android development.
But whatever the task preBuild is, if you make depend on all pullAssetsFlavorX tasks, then all those will get executed unless you disable them by some condition.
That you declare the tasks in the configuration for each flavor obviously does not mean this part of the configuration is not run.
So if configuration for all flavors is run, preBuild is made depending on all the pullAssetsFlavorX tasks.