// assembleTask for this flavor(dimension), created on demand if needed.
Task assembleTask = null;
ProductFlavorData defaultConfigData = basePlugin.getDefaultConfigData();
DefaultProductFlavor defaultConfig = defaultConfigData.getProductFlavor();
DefaultAndroidSourceSet defaultConfigSourceSet = defaultConfigData.getSourceSet();
final List<ConfigurationProvider> variantProviders = Lists.newArrayListWithCapacity(flavorDataList.length + 2);
Closure<Void> variantFilterClosure = basePlugin.getExtension().getVariantFilter();
final List<ProductFlavor> productFlavorList = (variantFilterClosure != null) ? Lists.<ProductFlavor>newArrayListWithCapacity(flavorDataList.length) : null;
for (BuildTypeData buildTypeData : buildTypes.values()) {
boolean ignore = false;
if (variantFilterClosure != null) {
productFlavorList.clear();
for (ProductFlavorData data : flavorDataList) {
productFlavorList.add(data.getProductFlavor());
}
variantFilter.reset(defaultConfig, buildTypeData.getBuildType(), productFlavorList);
variantFilterClosure.call(variantFilter);
ignore = variantFilter.isIgnore();
}
if (!ignore) {
if (assembleTask == null && flavorDataList.length > 1) {
assembleTask = createAssembleTask(flavorDataList);
project.getTasks().getByName("assemble").dependsOn(assembleTask);
}
/// add the container of dependencies
// the order of the libraries is important. In descending order:
// build types, flavors, defaultConfig.
variantProviders.clear();
variantProviders.add(buildTypeData);
VariantConfiguration variantConfig = new VariantConfiguration(
defaultConfig,
defaultConfigSourceSet,
buildTypeData.getBuildType(),
buildTypeData.getSourceSet(),
variantFactory.getVariantConfigurationType(),
signingOverride);
for (ProductFlavorData data : flavorDataList) {
String dimensionName = "";
DefaultProductFlavor productFlavor = data.getProductFlavor();
if (productFlavor instanceof GroupableProductFlavorDsl) {
dimensionName = ((GroupableProductFlavorDsl) productFlavor).getFlavorDimension();
}
variantConfig.addProductFlavor(
productFlavor,
data.getSourceSet(),
dimensionName
);
variantProviders.add(data.getMainProvider());
}
// now add the defaultConfig
variantProviders.add(basePlugin.getDefaultConfigData().getMainProvider());
// create the variant and get its internal storage object.
BaseVariantData variantData = variantFactory.createVariantData(variantConfig);
NamedDomainObjectContainer<AndroidSourceSet> sourceSetsContainer = extension
.getSourceSetsContainer();
DefaultAndroidSourceSet variantSourceSet = (DefaultAndroidSourceSet) sourceSetsContainer.maybeCreate(
variantConfig.getFullName());
variantConfig.setVariantSourceProvider(variantSourceSet);
// TODO: hmm this won't work
//variantProviders.add(new ConfigurationProviderImpl(project, variantSourceSet))
if (flavorDataList.length > 1) {
DefaultAndroidSourceSet multiFlavorSourceSet = (DefaultAndroidSourceSet) sourceSetsContainer.maybeCreate(variantConfig.getFlavorName());
variantConfig.setMultiFlavorSourceProvider(multiFlavorSourceSet);
// TODO: hmm this won't work
//variantProviders.add(new ConfigurationProviderImpl(project, multiFlavorSourceSet))
}