use of com.android.build.gradle.internal.VariantManager in project atlas by alibaba.
the class AtlasConfigurationHelper method getVariantManager.
public VariantManager getVariantManager() {
VariantManager variantManager = null;
BasePlugin appPlugin = project.getPlugins().findPlugin(AppPlugin.class);
if (null == appPlugin) {
appPlugin = project.getPlugins().findPlugin(LibraryPlugin.class);
}
if (appPlugin != null) {
try {
variantManager = (VariantManager) ReflectUtils.getField(BasePlugin.class, appPlugin, "variantManager");
} catch (Exception e) {
e.printStackTrace();
}
}
return variantManager;
}
use of com.android.build.gradle.internal.VariantManager in project atlas by alibaba.
the class BasePlugin method createExtension.
private void createExtension() {
final NamedDomainObjectContainer<BuildType> buildTypeContainer = project.container(BuildType.class, new BuildTypeFactory(instantiator, project, project.getLogger()));
final NamedDomainObjectContainer<ProductFlavor> productFlavorContainer = project.container(ProductFlavor.class, new ProductFlavorFactory(instantiator, project, project.getLogger(), extraModelInfo));
final NamedDomainObjectContainer<SigningConfig> signingConfigContainer = project.container(SigningConfig.class, new SigningConfigFactory(instantiator));
extension = project.getExtensions().create("android", getExtensionClass(), project, instantiator, androidBuilder, sdkHandler, buildTypeContainer, productFlavorContainer, signingConfigContainer, extraModelInfo, isLibrary());
// create the default mapping configuration.
project.getConfigurations().create("default" + VariantDependencies.CONFIGURATION_MAPPING).setDescription("Configuration for default mapping artifacts.");
project.getConfigurations().create("default" + VariantDependencies.CONFIGURATION_METADATA).setDescription("Metadata for the produced APKs.");
dependencyManager = new TDependencyManager(project, extraModelInfo, sdkHandler);
ndkHandler = new NdkHandler(project.getRootDir(), null, /* compileSkdVersion, this will be set in afterEvaluate */
"gcc", "");
taskManager = createTaskManager(project, androidBuilder, dataBindingBuilder, extension, sdkHandler, ndkHandler, dependencyManager, registry);
variantFactory = createVariantFactory();
variantManager = new VariantManager(project, androidBuilder, extension, variantFactory, taskManager, instantiator);
// Register a builder for the custom tooling model
ModelBuilder modelBuilder = new ModelBuilder(androidBuilder, variantManager, taskManager, extension, extraModelInfo, ndkHandler, new NativeLibraryFactoryImpl(ndkHandler), isLibrary(), AndroidProject.GENERATION_ORIGINAL);
registry.register(modelBuilder);
// Register a builder for the native tooling model
NativeModelBuilder nativeModelBuilder = new NativeModelBuilder(variantManager);
registry.register(nativeModelBuilder);
// map the whenObjectAdded callbacks on the containers.
signingConfigContainer.whenObjectAdded(new Action<SigningConfig>() {
@Override
public void execute(SigningConfig signingConfig) {
variantManager.addSigningConfig(signingConfig);
}
});
buildTypeContainer.whenObjectAdded(new Action<BuildType>() {
@Override
public void execute(BuildType buildType) {
SigningConfig signingConfig = signingConfigContainer.findByName(BuilderConstants.DEBUG);
buildType.init(signingConfig);
variantManager.addBuildType(buildType);
}
});
productFlavorContainer.whenObjectAdded(new Action<ProductFlavor>() {
@Override
public void execute(ProductFlavor productFlavor) {
variantManager.addProductFlavor(productFlavor);
}
});
// map whenObjectRemoved on the containers to throw an exception.
signingConfigContainer.whenObjectRemoved(new UnsupportedAction("Removing signingConfigs is not supported."));
buildTypeContainer.whenObjectRemoved(new UnsupportedAction("Removing build types is not supported."));
productFlavorContainer.whenObjectRemoved(new UnsupportedAction("Removing product flavors is not supported."));
// create default Objects, signingConfig first as its used by the BuildTypes.
variantFactory.createDefaultComponents(buildTypeContainer, productFlavorContainer, signingConfigContainer);
}
use of com.android.build.gradle.internal.VariantManager in project atlas by alibaba.
the class AtlasConfigurationHelper method configDependencies.
public void configDependencies(File awbConfigFile) {
Set<String> awbs = getAwbs(awbConfigFile);
AtlasDependencyManager atlasDependencyManager = new AtlasDependencyManager(project, new ExtraModelInfo(new ProjectOptions(project), project.getLogger()), awbs);
VariantManager variantManager = getVariantManager();
if (variantManager != null) {
variantManager.getVariantScopes().stream().forEach(variantScope -> atlasDependencyManager.resolveDependencies(variantScope.getVariantDependencies()));
}
}
Aggregations