# VariantExtension

[View Source](https://cs.android.com/search?q=file:com/android/build/api/variant/VariantExtension.kt+class:com.android.build.api.variant.VariantExtension) Added in 7.0.0


```
interface VariantExtension
```

<br />

*** ** * ** ***

Marker type for `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Variant` extension objects.

Variant extension must be registered using the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/AndroidComponentsExtension#registerExtension(com.android.build.api.variant.DslExtension,kotlin.Function1)` API and can be retrieved from a `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Variant` instance using the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/Variant#getExtension(java.lang.Class)` API.

Since this type will most likely be used as `https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html`'s input, your subtype should also extend `https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/Serializable.html`

This variant extension will be passed to all plugins that register a `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/variant/AndroidComponentsExtension#onVariants(com.android.build.api.variant.VariantSelector,kotlin.Function1)` block. In case several plugins modify some of the variant extension fields, it is primordial to define all the fields as a `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Property.html`. This will ensure that the tasks execution blocks that call `https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Property.html#get--` will get the final value, regardless of the order in which plugins are configured.

Example of a sub-type :
` abstract class VariantDslExtension @Inject constructor( // Do not keep a reference on the VariantExtensionConfig as it is not
serializable, // use the constructor to extract the values for the BuildType/ProductFlavor extensions // that can be obtained from the
VariantExtensionConfig. extensionConfig: VariantExtensionConfig<*> ): VariantExtension, java.io.Serializable { abstract val
variantSettingOne: Property abstract val variantSettingTwo: Property `

and this is the corresponding registration and instantiation code : ` androidComponents.registerExtension( DslExtension.Builder("dslExtension") .extendProjectWith(ProjectDslExtension::class.java) .build() ) { config -> project.objects.newInstance( VariantDslExtension::class.java, config ) } `