VariantBuilder

public interface VariantBuilder extends ComponentBuilder

Known direct subclasses
ApplicationVariantBuilder

Application specific variant object that contains properties that will determine the variant's build flow.

DynamicFeatureVariantBuilder
LibraryVariantBuilder

VariantBuilder type for library projects

TestVariantBuilder

VariantBuilder type for tests associated with a module.


Variant object that contains properties that must be set during configuration time as it changes the build flow for the variant.

Summary

Public methods

abstract boolean

Set to true if the variant's has any unit tests, false otherwise.

abstract Integer

Gets the maximum supported SDK Version for this variant.

abstract Integer

Gets or sets the minimum supported SDK Version for this variant.

abstract String

Gets or sets the minimum supported SDK Version for this variant as a Preview codename.

abstract int

Specifies the bytecode version to be generated.

abstract Integer

Gets or sets the target SDK Version for this variant as a Preview codename.

abstract String

Gets or sets the target SDK Version for this variant as a Preview codename.

abstract boolean

Set to true if the variant's has any unit tests, false otherwise.

abstract void
<T extends Object> registerExtension(
    @NonNull Class<@NonNull T> type,
    @NonNull T instance
)

Registers an extension object to the variant object.

abstract void
setEnableUnitTest(boolean enableUnitTest)

Set to true if the variant's has any unit tests, false otherwise.

abstract void

Gets the maximum supported SDK Version for this variant.

abstract void

Gets or sets the minimum supported SDK Version for this variant.

abstract void
setMinSdkPreview(String minSdkPreview)

Gets or sets the minimum supported SDK Version for this variant as a Preview codename.

abstract void
setRenderscriptTargetApi(int renderscriptTargetApi)

Specifies the bytecode version to be generated.

abstract void
setTargetSdk(Integer targetSdk)

Gets or sets the target SDK Version for this variant as a Preview codename.

abstract void
setTargetSdkPreview(String targetSdkPreview)

Gets or sets the target SDK Version for this variant as a Preview codename.

abstract void
setUnitTestEnabled(boolean unitTestEnabled)

Set to true if the variant's has any unit tests, false otherwise.

Inherited methods

From com.android.build.api.variant.ComponentBuilder
abstract boolean

Set to true if the variant is active and should be configured, false otherwise.

abstract boolean
abstract void
setEnable(boolean enable)

Set to true if the variant is active and should be configured, false otherwise.

abstract void
setEnabled(boolean enabled)
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.

Public methods

getEnableUnitTest

abstract boolean getEnableUnitTest()

Set to true if the variant's has any unit tests, false otherwise. Value is Boolean#True by default.

getMaxSdk

abstract Integer getMaxSdk()

Gets the maximum supported SDK Version for this variant.

getMinSdk

abstract Integer getMinSdk()

Gets or sets the minimum supported SDK Version for this variant. Setting this it will override previous calls of minSdk and minSdkPreview setters. Only one of minSdk and minSdkPreview should be set.

Returns
Integer

the minimum supported SDK Version or null if minSdkPreview was used to set it.

getMinSdkPreview

abstract String getMinSdkPreview()

Gets or sets the minimum supported SDK Version for this variant as a Preview codename. Setting this it will override previous calls of minSdk and minSdkPreview setters. Only one of minSdk and minSdkPreview should be set.

Returns
String

the minimum supported SDK Version or null if minSdk was used to set it.

getRenderscriptTargetApi

abstract int getRenderscriptTargetApi()

Specifies the bytecode version to be generated. We recommend you set this value to the lowest API level able to provide all the functionality you are using

Returns
int

the renderscript target api or -1 if not specified.

getTargetSdk

abstract Integer getTargetSdk()

Gets or sets the target SDK Version for this variant as a Preview codename. Setting this it will override previous calls of targetSdk and targetSdkPreview setters. Only one of targetSdk and targetSdkPreview should be set.

targetSdk is now managed by GeneratesApkBuilder instead of VariantBuilder.

Returns
Integer

the target SDK Version or null if targetSdkPreview was used to set it.

getTargetSdkPreview

abstract String getTargetSdkPreview()

Gets or sets the target SDK Version for this variant as a Preview codename. Setting this it will override previous calls of targetSdk and targetSdkPreview setters. Only one of targetSdk and targetSdkPreview should be set.

targetSdkPreview is now managed by GeneratesApkBuilder instead of VariantBuilder.

Returns
String

the target supported SDK Version or null if targetSdkPreview was used to set it.

getUnitTestEnabled

abstract boolean getUnitTestEnabled()

Set to true if the variant's has any unit tests, false otherwise. Value is Boolean#True by default.

registerExtension

abstract void <T extends Object> registerExtension(
    @NonNull Class<@NonNull T> type,
    @NonNull T instance
)

Registers an extension object to the variant object. Extension objects can be looked up during the AndroidComponentsExtension.onVariants callbacks by using the Variant.getExtension API.

This is very useful for third party plugins that want to attach some variant specific configuration object to the Android Gradle Plugin variant object and make it available to other plugins.

Parameters
@NonNull Class<@NonNull T> type

the registered object type (can be a supertype of instance), this is the type that must be passed to the Variant.getExtension API.

@NonNull T instance

the object to associate to the AGP Variant object.

setEnableUnitTest

abstract void setEnableUnitTest(boolean enableUnitTest)

Set to true if the variant's has any unit tests, false otherwise. Value is Boolean#True by default.

setMaxSdk

abstract void setMaxSdk(Integer maxSdk)

Gets the maximum supported SDK Version for this variant.

setMinSdk

abstract void setMinSdk(Integer minSdk)

Gets or sets the minimum supported SDK Version for this variant. Setting this it will override previous calls of minSdk and minSdkPreview setters. Only one of minSdk and minSdkPreview should be set.

Returns
void

the minimum supported SDK Version or null if minSdkPreview was used to set it.

setMinSdkPreview

abstract void setMinSdkPreview(String minSdkPreview)

Gets or sets the minimum supported SDK Version for this variant as a Preview codename. Setting this it will override previous calls of minSdk and minSdkPreview setters. Only one of minSdk and minSdkPreview should be set.

Returns
void

the minimum supported SDK Version or null if minSdk was used to set it.

setRenderscriptTargetApi

abstract void setRenderscriptTargetApi(int renderscriptTargetApi)

Specifies the bytecode version to be generated. We recommend you set this value to the lowest API level able to provide all the functionality you are using

Returns
void

the renderscript target api or -1 if not specified.

setTargetSdk

abstract void setTargetSdk(Integer targetSdk)

Gets or sets the target SDK Version for this variant as a Preview codename. Setting this it will override previous calls of targetSdk and targetSdkPreview setters. Only one of targetSdk and targetSdkPreview should be set.

targetSdk is now managed by GeneratesApkBuilder instead of VariantBuilder.

Returns
void

the target SDK Version or null if targetSdkPreview was used to set it.

setTargetSdkPreview

abstract void setTargetSdkPreview(String targetSdkPreview)

Gets or sets the target SDK Version for this variant as a Preview codename. Setting this it will override previous calls of targetSdk and targetSdkPreview setters. Only one of targetSdk and targetSdkPreview should be set.

targetSdkPreview is now managed by GeneratesApkBuilder instead of VariantBuilder.

Returns
void

the target supported SDK Version or null if targetSdkPreview was used to set it.

setUnitTestEnabled

abstract void setUnitTestEnabled(boolean unitTestEnabled)

Set to true if the variant's has any unit tests, false otherwise. Value is Boolean#True by default.