Android 12 Developer Preview is here! Try it out, and give us your feedback!

VariantBuilder

@Incubating interface VariantBuilder : ComponentBuilder, ActionableComponentObject
com.android.build.api.variant.VariantBuilder

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 Unit
registerExtension(type: Class<out T>, instance: T)

Registers an extension object to the variant object.

Properties

abstract Int?

Gets the maximum supported SDK Version for this variant.

abstract AndroidVersion

Gets the minimum supported SDK Version for this variant.

abstract Int

Specifies the bytecode version to be generated.

abstract AndroidVersion

Gets the target SDK version for this variant.

abstract Boolean

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

Inherited properties

Public methods

registerExtension

abstract fun <T : Any> registerExtension(
    type: Class<out T>,
    instance: T
): Unit

Registers an extension object to the variant object. Extension objects can be looked up during the com.android.build.api.extension.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
type: Class<out T> the registered object type (can be a supertype of instance), this is the type that must be passed to the Variant.getExtension API.
instance: T the object to associate to the AGP Variant object.

Properties

maxSdkVersion

abstract var maxSdkVersion: Int?

Gets the maximum supported SDK Version for this variant.

minSdkVersion

abstract var minSdkVersion: AndroidVersion

Gets the minimum supported SDK Version for this variant.

renderscriptTargetApi

abstract var renderscriptTargetApi: Int

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

Return
the renderscript target api or -1 if not specified.

targetSdkVersion

abstract var targetSdkVersion: AndroidVersion

Gets the target SDK version for this variant.

unitTestEnabled

abstract var unitTestEnabled: Boolean

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