Variant

public interface Variant extends 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 methods

abstract @NonNull MapProperty<@NonNull String, @NonNull BuildConfigField<@NonNull Serializable>>

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

abstract @NonNull List<@NonNull Component>

List containing this variant and all of its nestedComponents

abstract @NonNull MapProperty<@NonNull String, @NonNull Object>

Additional per variant experimental properties.

abstract T
<T extends Object> getExtension(@NonNull Class<@NonNull T> type)

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

abstract ExternalNativeBuild

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

abstract @NonNull MapProperty<@NonNull String, @NonNull String>

MapProperty of the variant's manifest placeholders.

abstract Integer

Gets the maximum supported SDK Version for this variant.

abstract Integer
abstract @NonNull AndroidVersion

Gets the minimum supported SDK Version for this variant.

abstract @NonNull AndroidVersion
abstract @NonNull List<@NonNull Component>

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

abstract @NonNull Packaging

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

abstract @NonNull ListProperty<@NonNull RegularFile>

List of proguard configuration files for this variant.

abstract @NonNull AndroidVersion

Gets the target SDK Version for this variant.

abstract UnitTest

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

abstract void
@Incubating
missingDimensionStrategy(
    @NonNull String dimension,
    @NonNull String requestedValues
)

Set up a new matching request for a given flavor dimension and value.

Inherited methods

From com.android.build.api.variant.Component
abstract @NonNull Configuration

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

abstract @NonNull Artifacts

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

abstract @NonNull FileCollection

Access to the variant's compile classpath.

abstract @NonNull Configuration

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

abstract @NonNull Instrumentation

Access to the variant's instrumentation options.

abstract @NonNull JavaCompilation

Access to the variant's java compilation options.

abstract @NonNull Provider<@NonNull String>

The namespace of the generated R and BuildConfig classes.

abstract @NonNull Configuration

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

abstract @NonNull Sources

Access to variant's source files.

abstract void

This method is deprecated. Will be removed in v9.0, use the instrumentation block.

abstract void
<ParamT extends InstrumentationParameters> transformClassesWith(
    @NonNull Class<@NonNull AsmClassVisitorFactory<@NonNull ParamT>> classVisitorFactoryImplClass,
    @NonNull InstrumentationScope scope,
    @NonNull Function1<@NonNull ParamT, Unit> instrumentationParamsConfig
)

This method is deprecated. Will be removed in v9.0, use the instrumentation block.

From com.android.build.api.variant.ComponentIdentity
abstract String

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

abstract String

The multi-flavor name of the variant.

abstract @NonNull String

Component's name.

abstract @NonNull List<@NonNull Pair<@NonNull String, @NonNull String>>

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

From com.android.build.api.variant.HasAndroidResources
abstract @NonNull Property<@NonNull Boolean>

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

abstract @NonNull MapProperty<@NonNull ResValue.Key, @NonNull ResValue>

Variant's ResValue which will be generated.

abstract @NonNull ResValue.Key

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

Public methods

getBuildConfigFields

abstract @NonNull MapProperty<@NonNull String, @NonNull BuildConfigField<@NonNull Serializable>> getBuildConfigFields()

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

getComponents

@Incubating
abstract @NonNull List<@NonNull ComponentgetComponents()

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

getExperimentalProperties

@Incubating
abstract @NonNull MapProperty<@NonNull String, @NonNull ObjectgetExperimentalProperties()

Additional per variant experimental properties.

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

getExtension

abstract T <T extends Object> getExtension(@NonNull Class<@NonNull T> type)

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.

getExternalNativeBuild

abstract ExternalNativeBuild getExternalNativeBuild()

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

getManifestPlaceholders

abstract @NonNull MapProperty<@NonNull String, @NonNull StringgetManifestPlaceholders()

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.

getMaxSdk

abstract Integer getMaxSdk()

Gets the maximum supported SDK Version for this variant.

getMaxSdkVersion

abstract Integer getMaxSdkVersion()

getMinSdk

abstract @NonNull AndroidVersion getMinSdk()

Gets the minimum supported SDK Version for this variant.

getMinSdkVersion

abstract @NonNull AndroidVersion getMinSdkVersion()

getNestedComponents

@Incubating
abstract @NonNull List<@NonNull ComponentgetNestedComponents()

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

getPackaging

abstract @NonNull Packaging getPackaging()

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

getProguardFiles

abstract @NonNull ListProperty<@NonNull RegularFilegetProguardFiles()

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.

getTargetSdkVersion

abstract @NonNull AndroidVersion getTargetSdkVersion()

Gets the target SDK Version for this variant.

getUnitTest

abstract UnitTest getUnitTest()

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

missingDimensionStrategy

@Incubating
abstract void missingDimensionStrategy(
    @NonNull String dimension,
    @NonNull String requestedValues
)

Set up a new matching request for a given flavor dimension and value.

Parameters
@NonNull String dimension

the flavor dimension

@NonNull String requestedValues

the flavor name(s)

See also
missingDimensionStrategy

To learn more, read d.android.com//build/build-variants.