ApplicationVariant

interface ApplicationVariant : GeneratesApk, Variant, HasAndroidTest, HasTestFixtures

Properties for the main Variant of an application.

Summary

Inherited functions

T? getExtension(type: Class<T>)

Returns an extension object registered via the VariantBuilder.registerExtension API or null if none were registered under the passed type.

ResValue.Key makeResValueKey(type: String, name: String)

Make a ResValue.Key to interact with resValues's MapProperty

Unit setAsmFramesComputationMode(mode: FramesComputationMode)

Sets the frame computation mode that will be applied to the bytecode of the classes instrumented by ASM visitors registered through transformClassesWith. The default mode is to copy frames.

When setting this multiple times, the mode with the highest enum value will be selected.

Unit transformClassesWith(classVisitorFactoryImplClass: Class<out AsmClassVisitorFactory<ParamT>>, scope: InstrumentationScope, instrumentationParamsConfig: (ParamT) -> Unit)

Registers an asm class visitor to instrument the classes defined by the given scope. An instance of the factory will be instantiated and used to create visitors for each class.

Example:

androidComponentsExtension.onVariants(selector().all(), {
    transformClassesWith(AsmClassVisitorFactoryImpl.class,
                         InstrumentationScope.Project) { params ->
        params.x = "value"
    }
    setAsmFramesComputationMode(COMPUTE_FRAMES_FOR_INSTRUMENTED_METHODS)
})

Properties

abstract Property<String>

Variant's application ID as present in the final manifest file of the APK.

abstract BundleConfig

Variant's information related to the bundle creation configuration.

abstract DependenciesInfo

Specify whether to include SDK dependency information in APKs and Bundles.

abstract List<VariantOutput>

Returns the final list of variant outputs.

abstract SigningConfig

Variant's signingConfig, initialized by the corresponding DSL element.

Inherited properties

AndroidResources androidResources

Variant's android resources processing configuration, initialized by the corresponding global DSL element.

ApkPackaging packaging

Variant's packagingOptions, initialized by the corresponding global DSL element.

Renderscript? renderscript

Variant specific settings for the renderscript compiler. This will return null when com.android.build.api.dsl.BuildFeatures.renderScript is false.

AndroidTest? androidTest

Variant's AndroidTest configuration, or null if android tests are disabled for this variant.

Artifacts artifacts

Access to the variant's buildable artifacts for build customization.

JavaCompilation javaCompilation

Access to the variant's java compilation options.

MapProperty<String, BuildConfigField<out Serializable>> buildConfigFields

Variant's BuildConfigField which will be generated in the BuildConfig class.

MapProperty<String, Any> experimentalProperties

Additional per variant experimental properties.

Initialized from com.android.build.api.dsl.CommonExtension.experimentalProperties

ExternalNativeBuild? externalNativeBuild

Variant's cmake ExternalNativeBuild, initialized by merging the product flavor values or null if no cmake external build is configured for this variant.

MapProperty<String, String> manifestPlaceholders

MapProperty of the variant's manifest placeholders.

Placeholders are organized with a key and a value. The value is a String that will be used as is in the merged manifest.

Int? maxSdkVersion

Gets the maximum supported SDK Version for this variant.

AndroidVersion minSdkVersion

Gets the minimum supported SDK Version for this variant.

Provider<String> namespace

The namespace of the generated R and BuildConfig classes. Also, the namespace used to resolve any relative class names that are declared in the AndroidManifest.xml.

List<Component> nestedComponents

List of the components nested in this variant, the returned list will contain:

Use this list to do operations on all nested components of this variant without having to manually check whether the variant has each component.

Example:

androidComponents.onVariants(selector().withName("debug")) {
    // will return unitTests, androidTests, testFixtures for the debug variant (if enabled).
    nestedComponents.forEach { component ->
        component.transformClassesWith(NestedComponentsClassVisitorFactory::class.java,
                                       InstrumentationScope.Project) {}
    }
}

ListProperty<RegularFile> proguardFiles

List of proguard configuration files for this variant. The list is initialized from the corresponding DSL element, and cannot be queried at configuration time. At configuration time, you can only add new elements to the list.

This list will be initialized from com.android.build.api.dsl.VariantDimension#proguardFile for non test related variants and from com.android.build.api.dsl.VariantDimension.testProguardFiles for test related variants.

AndroidVersion targetSdkVersion

Gets the target SDK Version for this variant.

UnitTest? unitTest

Variant's UnitTest, or null if the unit tests for this variant are disabled.

String? buildType

Build type name, might be replaced with access to locked DSL object once ready.

String? flavorName

The multi-flavor name of the variant.

This does not include the build type. If no flavors are present, this will return null

The full name of the variant is queried via name.

String name

Component's name.

List<Pair<String, String>> productFlavors

List of flavor names, might be replaced with access to locked DSL objects once ready.

The order is properly sorted based on the associated dimension order.

Property<Boolean> pseudoLocalesEnabled

Variant's is pseudo locales enabled, initialized by the corresponding DSL elements.

MapProperty<ResValue.Key, ResValue> resValues

Variant's ResValue which will be generated.

TestFixtures? testFixtures

Variant's TestFixtures, or null if the test fixtures for this variant are disabled.

Properties

applicationId

abstract val applicationId: Property<String>

Variant's application ID as present in the final manifest file of the APK.

Setting this value will override anything set via the DSL with com.android.build.api.dsl.ApplicationBaseFlavor.applicationId, and com.android.build.api.dsl.ApplicationVariantDimension.applicationIdSuffix

bundleConfig

abstract val bundleConfig: BundleConfig

Variant's information related to the bundle creation configuration.

Return
Variant's BundleConfig.

dependenciesInfo

abstract val dependenciesInfo: DependenciesInfo

Specify whether to include SDK dependency information in APKs and Bundles.

outputs

abstract val outputs: List<VariantOutput>

Returns the final list of variant outputs.

Return
read only list of VariantOutput for this variant.

signingConfig

abstract val signingConfig: SigningConfig

Variant's signingConfig, initialized by the corresponding DSL element.

Return
Variant's config or null if the variant is not configured for signing.