This question in continuation of my other question, which i want to improve further.
I am being able to group flavors (having common configuration) under sourceSets
with the following code :
(got it from a genius in the linked question above)
import com.android.build.gradle.api.AndroidSourceSet
android {
sourceSets {
[flavor2, flavor4].each { AndroidSourceSet ss ->
ss.assets.srcDirs = ['repo-assets/flavor2']
ss.res.srcDirs = ['repo-res/flavor2']
}
}
}
Now, I was wondering if the list [flavor2, flavor4]
could be pulled from any of the following:
- An XML file over which i can iterate to get all flavors (which i'll put there)
- A CSV file over which i can iterate and fetch values.
- A custom class which i can write in a separate file and fetch data from static members in the class.
In addition to the flavor name, I intend to store the following in the external source (one of above):
- application id (which i will pull to
productFlavors
) - ad unit ids (two per flavor)
- some other custom values like category etc.
PORPOSE: I want to write a generic piece of code to iterate and dynamically create the productFlavors
and sourceSets
. I have generalized sourceSets
to almost 90% and one block is now sufficing for all flavors.
It looks something like this now:
sourceSets {
[flavor1, flavor2, flavor3 ...].each { AndroidSourceSet ss ->
ss.assets.srcDirs = ['repo-assets/' + ss.name.split('_')[0]]
ss.res.srcDirs = ['repo-mipmap/' + ss.name.split('_')[0] , 'repo-strings/' + ss.name]
}
}
Also want to do the same thing for productFlavors
as hinted above.
STUCK AT: getting the list [flavor2, flavor4]
in the code above from an external source (along with a few additional fields per flavor as listed above).
I see methods like
productFlavors.add()
productFlavors.addAll()
but am not quite sure about how to go about using these. As the methods are available I'm sure it is possible to do what I'm trying to.
Has anyone done this and has some pointers?