# VariantBuilder

# VariantBuilder

<br />

```
interface VariantBuilder : ComponentIdentity, ComponentBuilder
```

<br />

Known direct subclasses  
[ApplicationVariantBuilder](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/ApplicationVariantBuilder),[DynamicFeatureVariantBuilder](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/DynamicFeatureVariantBuilder),[LibraryVariantBuilder](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/LibraryVariantBuilder),[TestVariantBuilder](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/TestVariantBuilder)  

|---------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ApplicationVariantBuilder](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/ApplicationVariantBuilder)       | Application specific variant object that contains properties that will determine the variant's build flow.                                                          |
| [DynamicFeatureVariantBuilder](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/DynamicFeatureVariantBuilder) |                                                                                                                                                                     |
| [LibraryVariantBuilder](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/LibraryVariantBuilder)               | [VariantBuilder](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder)type for library projects                |
| [TestVariantBuilder](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/TestVariantBuilder)                     | [VariantBuilder](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/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 functions                                                                                                                                                                                                                                                      ||
|------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `<T : `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`?> `[registerExtension](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#registerExtension(java.lang.Class,kotlin.Any))`(type: `[Class](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Class.html)`<T?>?, instance: T?)` Registers an extension object to the variant object. |

|                                                                                                                                                 ### Public properties                                                                                                                                                  ||
|-------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)  | [enableUnitTest](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#enableUnitTest()) Set to`true`if the variant's has any unit tests, false otherwise.                    |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`?`       | [maxSdk](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#maxSdk()) Gets the maximum supported SDK Version for this variant.                                             |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`?`       | [minSdk](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#minSdk()) Gets or sets the minimum supported SDK Version for this variant.                                     |
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` | [minSdkPreview](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#minSdkPreview()) Gets or sets the minimum supported SDK Version for this variant as a Preview codename. |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)          | [renderscriptTargetApi](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#renderscriptTargetApi()) Specifies the bytecode version to be generated.                        |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`?`       | [targetSdk](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#targetSdk()) Gets or sets the target SDK Version for this variant as a Preview codename.                    |
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` | [targetSdkPreview](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#targetSdkPreview()) Gets or sets the target SDK Version for this variant as a Preview codename.      |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)  | [unitTestEnabled](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#unitTestEnabled()) Set to`true`if the variant's has any unit tests, false otherwise.                  |

## Public functions

### registerExtension

```
fun <T : Any?> registerExtension(type: Class<T?>?, instance: T?): Unit
```

Registers an extension object to the variant object. Extension objects can be looked up during the[AndroidComponentsExtension.onVariants](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/AndroidComponentsExtension#onVariants(com.android.build.api.variant.VariantSelector,kotlin.Function1))callbacks by using the[Variant.getExtension](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/Variant#getExtension(java.lang.Class))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](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Class.html)`<T?>?` | the registered object type (can be a supertype of[instance](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#registerExtension(java.lang.Class,kotlin.Any))), this is the type that must be passed to the[Variant.getExtension](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/Variant#getExtension(java.lang.Class))API. |
| `instance: T?`                                                                                            | the object to associate to the AGP Variant object.                                                                                                                                                                                                                                                                                                                                                                             |

## Public properties

### enableUnitTest

```
val enableUnitTest: Boolean
```

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

### maxSdk

```
val maxSdk: Int?
```

Gets the maximum supported SDK Version for this variant.  

### minSdk

```
val minSdk: Int?
```

Gets or sets the minimum supported SDK Version for this variant. Setting this it will override previous calls of[minSdk](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#minSdk())and[minSdkPreview](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#minSdkPreview())setters. Only one of[minSdk](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#minSdk())and[minSdkPreview](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#minSdkPreview())should be set.  

|                                                                                                                                         Returns                                                                                                                                          ||
|-------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`?` | the minimum supported SDK Version or null if[minSdkPreview](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#minSdkPreview())was used to set it. |

### minSdkPreview

```
val minSdkPreview: String?
```

Gets or sets the minimum supported SDK Version for this variant as a Preview codename. Setting this it will override previous calls of[minSdk](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#minSdk())and[minSdkPreview](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#minSdkPreview())setters. Only one of[minSdk](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#minSdk())and[minSdkPreview](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#minSdkPreview())should be set.  

|                                                                                                                                     Returns                                                                                                                                      ||
|-------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` | the minimum supported SDK Version or null if[minSdk](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#minSdk())was used to set it. |

### renderscriptTargetApi

```
val 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  

|                                                             Returns                                                             ||
|----------------------------------------------------------------------------|-----------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | the renderscript target api or -1 if not specified. |

### targetSdk

```
val targetSdk: Int?
```

Gets or sets the target SDK Version for this variant as a Preview codename. Setting this it will override previous calls of[targetSdk](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#targetSdk())and[targetSdkPreview](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#targetSdkPreview())setters. Only one of[targetSdk](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#targetSdk())and[targetSdkPreview](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#targetSdkPreview())should be set.  

|                                                                                                                                       Returns                                                                                                                                       ||
|-------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`?` | the target SDK Version or null if[targetSdkPreview](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#targetSdkPreview())was used to set it. |

### targetSdkPreview

```
val targetSdkPreview: String?
```

Gets or sets the target SDK Version for this variant as a Preview codename. Setting this it will override previous calls of[targetSdk](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#targetSdk())and[targetSdkPreview](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#targetSdkPreview())setters. Only one of[targetSdk](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#targetSdk())and[targetSdkPreview](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#targetSdkPreview())should be set.  

|                                                                                                                                               Returns                                                                                                                                               ||
|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` | the target supported SDK Version or null if[targetSdkPreview](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/VariantBuilder#targetSdkPreview())was used to set it. |

### unitTestEnabled

```
val unitTestEnabled: Boolean
```

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