Search in sources :

Example 1 with ModelBuilder

use of com.android.build.gradle.internal.model.ModelBuilder 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);
}
Also used : SigningConfig(com.android.build.gradle.internal.dsl.SigningConfig) TDependencyManager(com.android.build.gradle.internal.TDependencyManager) ProductFlavor(com.android.build.gradle.internal.dsl.ProductFlavor) NdkHandler(com.android.build.gradle.internal.ndk.NdkHandler) SigningConfigFactory(com.android.build.gradle.internal.dsl.SigningConfigFactory) ModelBuilder(com.android.build.gradle.internal.model.ModelBuilder) NativeModelBuilder(com.android.build.gradle.internal.model.NativeModelBuilder) ProductFlavorFactory(com.android.build.gradle.internal.dsl.ProductFlavorFactory) BuildTypeFactory(com.android.build.gradle.internal.dsl.BuildTypeFactory) NativeLibraryFactoryImpl(com.android.build.gradle.internal.NativeLibraryFactoryImpl) BuildType(com.android.build.gradle.internal.dsl.BuildType) VariantManager(com.android.build.gradle.internal.VariantManager) NativeModelBuilder(com.android.build.gradle.internal.model.NativeModelBuilder)

Aggregations

NativeLibraryFactoryImpl (com.android.build.gradle.internal.NativeLibraryFactoryImpl)1 TDependencyManager (com.android.build.gradle.internal.TDependencyManager)1 VariantManager (com.android.build.gradle.internal.VariantManager)1 BuildType (com.android.build.gradle.internal.dsl.BuildType)1 BuildTypeFactory (com.android.build.gradle.internal.dsl.BuildTypeFactory)1 ProductFlavor (com.android.build.gradle.internal.dsl.ProductFlavor)1 ProductFlavorFactory (com.android.build.gradle.internal.dsl.ProductFlavorFactory)1 SigningConfig (com.android.build.gradle.internal.dsl.SigningConfig)1 SigningConfigFactory (com.android.build.gradle.internal.dsl.SigningConfigFactory)1 ModelBuilder (com.android.build.gradle.internal.model.ModelBuilder)1 NativeModelBuilder (com.android.build.gradle.internal.model.NativeModelBuilder)1 NdkHandler (com.android.build.gradle.internal.ndk.NdkHandler)1