Variant

interface Variant : Component, HasAndroidResources

Known direct subclasses
ApplicationVariant

Properties for the main Variant of an application.

DynamicFeatureVariant
LibraryVariant

Variant for Library projects

TestVariant

Variant for test-only modules.


Parent interface for all types of variants.

Summary

Public functions

T?
<T : Any?> getExtension(type: Class<T>)

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

Public properties

MapProperty<StringBuildConfigField<Serializable>>

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

List<Component>

List containing this variant and all of its nestedComponents

MapProperty<StringAny>

Additional per variant experimental properties.

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<StringString>

MapProperty of the variant's manifest placeholders.

Int?

Gets the maximum supported SDK Version for this variant.

AndroidVersion

Gets the minimum supported SDK Version for this variant.

Provider<String>

The namespace of the generated R and BuildConfig classes.

List<Component>

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

Packaging

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

ListProperty<RegularFile>

List of proguard configuration files for this variant.

AndroidVersion

Gets the target SDK Version for this variant.

UnitTest?

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

Inherited functions

From class com.android.build.api.variant.Component
Unit

This function is deprecated. Use the instrumentation block.

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

This function is deprecated. Use the instrumentation block.

From class com.android.build.api.variant.HasAndroidResources
ResValue.Key
makeResValueKey(type: String, name: String)

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

Inherited properties

From class com.android.build.api.variant.Component
Configuration

Access to the variant's annotation processor Configuration; for example, the debugAnnotationProcessor Configuration for the debug variant.

Artifacts

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

FileCollection

Access to the variant's compile classpath.

Configuration

Access to the variant's compile Configuration; for example, the debugCompileClasspath Configuration for the debug variant.

Instrumentation

Access to the variant's instrumentation options.

JavaCompilation

Access to the variant's java compilation options.

Configuration

Access to the variant's runtime Configuration; for example, the debugRuntimeClasspath Configuration for the debug variant.

Sources

Access to variant's source files.

From class com.android.build.api.variant.ComponentIdentity
String?

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

String?

The multi-flavor name of the variant.

String

Component's name.

List<Pair<StringString>>

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

From class com.android.build.api.variant.HasAndroidResources
Property<Boolean>

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

MapProperty<ResValue.KeyResValue>

Variant's ResValue which will be generated.

Public functions

getExtension

fun <T : Any?> getExtension(type: Class<T>): T?

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

Returns
T?

the registered object or null.

Public properties

buildConfigFields

val buildConfigFieldsMapProperty<StringBuildConfigField<Serializable>>

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

components

val componentsList<Component>

List containing this variant and all of its nestedComponents

Example:

androidComponents.onVariants(selector().withName("debug")) {
// components contains the debug variant along with its unitTests, androidTests, and
// testFixtures (if enabled).
components.forEach { component ->
component.runtimeConfiguration
.resolutionStrategy
.dependencySubstitution {
substitute(project(":foo")).using(project(":bar"))
}
}
}

experimentalProperties

val experimentalPropertiesMapProperty<StringAny>

Additional per variant experimental properties.

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

externalNativeBuild

val externalNativeBuildExternalNativeBuild?

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

manifestPlaceholders

val manifestPlaceholdersMapProperty<StringString>

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.

Returns
MapProperty<StringString>

the MapProperty with keys as String

maxSdkVersion

val maxSdkVersionInt?

Gets the maximum supported SDK Version for this variant.

minSdkVersion

val minSdkVersionAndroidVersion

Gets the minimum supported SDK Version for this variant.

namespace

val namespaceProvider<String>

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.

nestedComponents

val nestedComponentsList<Component>

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) {}
}
}

packaging

val packagingPackaging

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

proguardFiles

val proguardFilesListProperty<RegularFile>

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.

targetSdkVersion

val targetSdkVersionAndroidVersion

Gets the target SDK Version for this variant.

unitTest

val unitTestUnitTest?

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