Variant
interface Variant : Component, HasAndroidResources
ApplicationVariant |
Properties for the main Variant of an application. |
DynamicFeatureVariant |
|
LibraryVariant |
|
TestVariant |
|
Parent interface for all types of variants.
Summary
Public functions |
|
---|---|
T? |
<T : Any?> getExtension(type: Class<T>) Returns an extension object registered via the |
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? |
This property is deprecated. Will be removed in v9.0 |
AndroidVersion |
Gets the minimum supported SDK Version for this variant. |
AndroidVersion |
This property is deprecated. Will be removed in v9.0 |
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 |
This property is deprecated. Will be removed in v9.0 |
UnitTest? |
This property is deprecated. Will be removed in v9.0 |
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. |
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
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 |
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 variantHasAndroidTest
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.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.
unitTest
val unitTest: UnitTest?
Variant's UnitTest
, or null if the unit tests for this variant are disabled.