Variant
interface Variant : Component, HasAndroidResources
ApplicationVariant |
Model for application components that only contains build-time properties. |
DynamicFeatureVariant |
Model for dynamic feature components that only contains build-time properties. |
LibraryVariant |
Model for library components that only contains build-time properties. |
TestVariant |
Model for test components that only contains build-time properties. |
Model for variant components that only contains build-time properties
Variant components are the main output of the plugin (e.g. APKs, AARs). They contain references to optional secondary components (tests, fixtures)
It is the object passed to the AndroidComponentsExtension.onVariants
method, like this:
androidComponents {
onVariants(selector().all()) { variant: Variant ->
}
}
Note that depending on the actual implementation of AndroidComponentsExtension
, the object received may be of a child type. For instance ApplicationAndroidComponentsExtension.onVariants
will pass ApplicationVariant
to the lambda.
See here for more information
Summary
Public functions |
|
---|---|
T? |
<T : Any?> getExtension(type: Class<T>) Returns an extension object registered via the |
Unit |
@Incubating Set up a new matching request for a given flavor dimension and value. |
Public properties |
|
---|---|
MapProperty<String, BuildConfigField<Serializable>> |
Variant's |
List<Component> |
List containing this variant and all of its |
MapProperty<String, Any> |
Additional per variant experimental properties. |
ExternalNativeBuild? |
Variant's cmake |
MapProperty<String, String> |
|
Int? |
Gets the maximum supported SDK Version for this variant. |
Int? |
|
AndroidVersion |
Gets the minimum supported SDK Version for this variant. |
AndroidVersion |
|
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 |
Inherited functions |
||||||
---|---|---|---|---|---|---|
|
||||||
|
Inherited properties |
||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||
|
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. |
missingDimensionStrategy
@Incubating
fun missingDimensionStrategy(
dimension: String,
vararg requestedValues: String
): Unit
Set up a new matching request for a given flavor dimension and value.
See also | |
---|---|
missingDimensionStrategy |
To learn more, read d.android.com//build/build-variants. |
Public properties
buildConfigFields
val buildConfigFields: MapProperty<String, BuildConfigField<Serializable>>
Variant's BuildConfigField
which will be generated in the BuildConfig class.
components
val components: List<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 experimentalProperties: MapProperty<String, Any>
Additional per variant experimental properties.
Initialized from com.android.build.api.dsl.CommonExtension.experimentalProperties
Values provided should not be based on a Task execution result, as most of these properties are read during configuration.
externalNativeBuild
val 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.
manifestPlaceholders
val manifestPlaceholders: MapProperty<String, String>
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<String, String> |
the |
minSdk
val minSdk: AndroidVersion
Gets the minimum supported SDK Version for this variant.
nestedComponents
val nestedComponents: List<Component>
List of the components nested in this variant, the returned list will contain:
-
UnitTest
component if the unit tests for this variant are enabled, -
AndroidTest
component if this variantHasDeviceTests
and android tests for this variant are enabled, -
TestFixtures
component if this variantHasTestFixtures
and test fixtures for this variant are enabled.
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.instrumentation.transformClassesWith(NestedComponentsClassVisitorFactory::class.java,
InstrumentationScope.Project) {}
}
}
packaging
val packaging: Packaging
Variant's packagingOptions, initialized by the corresponding global DSL element.
proguardFiles
val proguardFiles: ListProperty<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 targetSdkVersion: AndroidVersion
Gets the target SDK Version for this variant.