BaseFlavor

Added in 4.2.0

interface BaseFlavor : VariantDimension

Known direct subclasses
ApplicationBaseFlavor

Shared properties between ApplicationProductFlavor and ApplicationDefaultConfig

DefaultConfig

Specifies defaults for variant properties that the Android plugin applies to all build variants.

DynamicFeatureBaseFlavor

Shared properties between DSL objects DynamicFeatureProductFlavor and DynamicFeatureDefaultConfig

LibraryBaseFlavor

Shared properties between LibraryProductFlavor and LibraryDefaultConfig

ProductFlavor

Encapsulates all product flavors properties for this project.

TestBaseFlavor

Shared properties between TestProductFlavor and TestDefaultConfig

Known indirect subclasses
ApplicationDefaultConfig

Specifies defaults for properties that the Android application plugin applies to all build variants.

ApplicationProductFlavor

Encapsulates all product flavors properties for application projects.

DynamicFeatureDefaultConfig

Specifies defaults for properties that the Android dynamic-feature plugin applies to all build variants.

DynamicFeatureProductFlavor

Encapsulates all product flavors properties for dynamic feature projects.

LibraryDefaultConfig

Specifies defaults for properties that the Android library plugin applies to all build variants.

LibraryProductFlavor

Encapsulates all product flavors properties for library projects.

TestDefaultConfig

Specifies defaults for properties that the Android test plugin applies to all build variants.

TestProductFlavor

Encapsulates all product flavors properties for test projects.


Shared properties between DSL objects ProductFlavor and DefaultConfig

Summary

Public functions

String

The name of the flavor.

Unit

Copies all properties from the given flavor.

Unit
minSdkVersion(minSdkVersion: Int)

This function is deprecated. Replaced by minSdk property

Unit
minSdkVersion(minSdkVersion: String?)

This function is deprecated. Replaced by minSdkPreview property

Unit
missingDimensionStrategy(dimension: String, requestedValue: String)

Specifies a flavor that the plugin should try to use from a given dimension in a dependency.

Unit
missingDimensionStrategy(
    dimension: String,
    requestedValues: List<String>
)

Specifies a sorted list of flavors that the plugin should try to use from a given dimension in a dependency.

Unit
missingDimensionStrategy(
    dimension: String,
    vararg requestedValues: String
)

Specifies a sorted list of flavors that the plugin should try to use from a given dimension in a dependency.

Unit
resConfig(config: String)

This function is deprecated. Support for resource configurations will be removed.

Unit

This function is deprecated. Support for resource configurations will be removed.

Unit
resConfigs(vararg config: String)

This function is deprecated. Support for resource configurations will be removed.

Unit
setMinSdkVersion(minSdkVersion: Int)

This function is deprecated. Replaced by minSdk property

Unit
setMinSdkVersion(minSdkVersion: String?)

This function is deprecated. Replaced by minSdkPreview property

Any?
setTestFunctionalTest(testFunctionalTest: Boolean)

This function is deprecated. Replaced by testFunctionalTest property

Any?
setTestHandleProfiling(testHandleProfiling: Boolean)

This function is deprecated. Replaced by testFunctionalTest property

Any?
setTestInstrumentationRunnerArguments(
    testInstrumentationRunnerArguments: MutableMap<StringString>
)

This function is deprecated. Replaced by testInstrumentationRunnerArguments property

Unit

This function is deprecated. Replaced by testInstrumentationRunnerArguments property

Unit

This function is deprecated. Replaced by testInstrumentationRunnerArguments property

Unit

Configures VectorDrawables.

Public properties

Int?

The minimum SDK version.

String?

The minimum SDK version.

Boolean?

Whether the renderscript code should be compiled to generate C/C++ bindings.

Boolean?

Whether the renderscript BLAS support lib should be used to make it compatible with older versions of Android.

Boolean?

Whether the renderscript code should be compiled in support mode to make it compatible with older versions of Android.

Int?

The renderscript target api, or null if not specified.

MutableSet<String>

This property is deprecated. Support for resource configurations will be removed.

String?

Test application ID.

Boolean?

See instrumentation.

Boolean?

See instrumentation.

String?

Test instrumentation runner class name.

MutableMap<StringString>

Test instrumentation runner custom arguments.

VectorDrawables

Options to configure the build-time support for vector drawables.

Boolean?

Whether to enable unbundling mode for embedded wear app.

Inherited functions

From com.android.build.api.dsl.VariantDimension
Unit
addManifestPlaceholders(manifestPlaceholders: Map<StringAny>)

Adds manifest placeholders.

Unit
buildConfigField(type: String, name: String, value: String)

Adds a new field to the generated BuildConfig class.

Unit

Encapsulates per-variant CMake and ndk-build configurations for your external native build.

Unit

Options for configuring Java compilation.

Unit
ndk(action: Ndk.() -> Unit)

Encapsulates per-variant configurations for the NDK, such as ABI filters.

Unit
Any
proguardFile(proguardFile: Any)

Adds a new ProGuard configuration file.

Any
proguardFiles(vararg files: Any)

Adds new ProGuard configuration files.

Unit
resValue(type: String, name: String, value: String)

Adds a new generated resource.

Void?
setManifestPlaceholders(manifestPlaceholders: Map<StringAny>)

This function is deprecated. Use manifestPlaceholders property instead

Any
setProguardFiles(proguardFileIterable: Iterable<*>)

Replaces the ProGuard configuration files.

Unit
shaders(action: Shaders.() -> Unit)

Configure the shader compiler options.

Any
testProguardFile(proguardFile: Any)

Adds a proguard rule file to be used when processing test code.

Any
testProguardFiles(vararg proguardFiles: Any)

Adds proguard rule files to be used when processing test code.

Inherited properties

From com.android.build.api.dsl.VariantDimension
ExternalNativeBuildFlags

Encapsulates per-variant CMake and ndk-build configurations for your external native build.

JavaCompileOptions

Options for configuring Java compilation.

MutableMap<StringAny>

The manifest placeholders.

File?

This property is deprecated. This property is deprecated.

File?

Text file with additional ProGuard rules to be used to determine which classes are compiled into the main dex file.

Ndk

Encapsulates per-variant configurations for the NDK, such as ABI filters.

Optimization
MutableList<File>

Specifies the ProGuard configuration files that the plugin should use.

Shaders

Options for configuring the shader compiler.

MutableList<File>

The collection of proguard rule files to be used when processing test code.

Public functions

getName

Added in 4.2.0
fun getName(): String

The name of the flavor.

initWith

Added in 7.1.0
fun initWith(that: BaseFlavor): Unit

Copies all properties from the given flavor.

It can be used like this:

android.productFlavors {
paid {
initWith free
// customize...
}
}

minSdkVersion

Added in 7.0.0
Deprecated in 7.0.0
fun minSdkVersion(minSdkVersion: Int): Unit

minSdkVersion

Added in 7.0.0
Deprecated in 7.0.0
fun minSdkVersion(minSdkVersion: String?): Unit

missingDimensionStrategy

Added in 7.0.0
fun missingDimensionStrategy(dimension: String, requestedValue: String): Unit

Specifies a flavor that the plugin should try to use from a given dimension in a dependency.

Android plugin 3.0.0 and higher try to match each variant of your module with the same one from its dependencies. For example, consider if both your app and its dependencies include a "tier" /studio/build/build-variants.html#flavor-dimensions, with flavors "free" and "paid". When you build a "freeDebug" version of your app, the plugin tries to match it with "freeDebug" versions of the local library modules the app depends on.

However, there may be situations in which a library dependency includes a flavor dimension that your app does not. For example, consider if a library dependency includes flavors for a "minApi" dimension, but your app includes flavors for only the "tier" dimension. So, when you want to build the "freeDebug" version of your app, the plugin doesn't know whether to use the "minApi23Debug" or "minApi18Debug" version of the dependency, and you'll see an error message similar to the following:

Error:Failed to resolve: Could not resolve project :mylibrary.
Required by:
project :app

In this type of situation, use missingDimensionStrategy in the com.android.build.gradle.internal.dsl.DefaultConfig.html block to specify the default flavor the plugin should select from each missing dimension, as shown in the sample below. You can also override your selection in the com.android.build.gradle.internal.dsl.ProductFlavor.html block, so each flavor can specify a different matching strategy for a missing dimension. (Tip: you can also use this property if you simply want to change the matching strategy for a dimension that exists in both the app and its dependencies.)

// In the app's build.gradle file.
android {
defaultConfig {
// Specifies a flavor that the plugin should try to use from
// a given dimension. The following tells the plugin that, when encountering
// a dependency that includes a "minApi" dimension, it should select the
// "minApi18" flavor.
missingDimensionStrategy 'minApi', 'minApi18'
// You should specify a missingDimensionStrategy property for each
// dimension that exists in a local dependency but not in your app.
missingDimensionStrategy 'abi', 'x86'
}
flavorDimensions 'tier'
productFlavors {
free {
dimension 'tier'
// You can override the default selection at the product flavor
// level by configuring another missingDimensionStrategy property
// for the "minApi" dimension.
missingDimensionStrategy 'minApi', 'minApi23'
}
paid { }
}
}

missingDimensionStrategy

Added in 7.0.0
fun missingDimensionStrategy(
    dimension: String,
    requestedValues: List<String>
): Unit

Specifies a sorted list of flavors that the plugin should try to use from a given dimension in a dependency.

Android plugin 3.0.0 and higher try to match each variant of your module with the same one from its dependencies. For example, consider if both your app and its dependencies include a "tier" /studio/build/build-variants.html#flavor-dimensions, with flavors "free" and "paid". When you build a "freeDebug" version of your app, the plugin tries to match it with "freeDebug" versions of the local library modules the app depends on.

However, there may be situations in which a library dependency includes a flavor dimension that your app does not. For example, consider if a library dependency includes flavors for a "minApi" dimension, but your app includes flavors for only the "tier" dimension. So, when you want to build the "freeDebug" version of your app, the plugin doesn't know whether to use the "minApi23Debug" or "minApi18Debug" version of the dependency, and you'll see an error message similar to the following:

Error:Failed to resolve: Could not resolve project :mylibrary.
Required by:
project :app

In this type of situation, use missingDimensionStrategy in the com.android.build.gradle.internal.dsl.DefaultConfig.html block to specify the default flavor the plugin should select from each missing dimension, as shown in the sample below. You can also override your selection in the com.android.build.gradle.internal.dsl.ProductFlavor.html block, so each flavor can specify a different matching strategy for a missing dimension. (Tip: you can also use this property if you simply want to change the matching strategy for a dimension that exists in both the app and its dependencies.)

// In the app's build.gradle file.
android {
defaultConfig {
// Specifies a flavor that the plugin should try to use from
// a given dimension. The following tells the plugin that, when encountering
// a dependency that includes a "minApi" dimension, it should select the
// "minApi18" flavor.
missingDimensionStrategy 'minApi', 'minApi18'
// You should specify a missingDimensionStrategy property for each
// dimension that exists in a local dependency but not in your app.
missingDimensionStrategy 'abi', 'x86'
}
flavorDimensions 'tier'
productFlavors {
free {
dimension 'tier'
// You can override the default selection at the product flavor
// level by configuring another missingDimensionStrategy property
// for the "minApi" dimension.
missingDimensionStrategy 'minApi', 'minApi23'
}
paid { }
}
}

missingDimensionStrategy

Added in 7.0.0
fun missingDimensionStrategy(
    dimension: String,
    vararg requestedValues: String
): Unit

Specifies a sorted list of flavors that the plugin should try to use from a given dimension in a dependency.

Android plugin 3.0.0 and higher try to match each variant of your module with the same one from its dependencies. For example, consider if both your app and its dependencies include a "tier" /studio/build/build-variants.html#flavor-dimensions, with flavors "free" and "paid". When you build a "freeDebug" version of your app, the plugin tries to match it with "freeDebug" versions of the local library modules the app depends on.

However, there may be situations in which a library dependency includes a flavor dimension that your app does not. For example, consider if a library dependency includes flavors for a "minApi" dimension, but your app includes flavors for only the "tier" dimension. So, when you want to build the "freeDebug" version of your app, the plugin doesn't know whether to use the "minApi23Debug" or "minApi18Debug" version of the dependency, and you'll see an error message similar to the following:

Error:Failed to resolve: Could not resolve project :mylibrary.
Required by:
project :app

In this type of situation, use missingDimensionStrategy in the com.android.build.gradle.internal.dsl.DefaultConfig.html block to specify the default flavor the plugin should select from each missing dimension, as shown in the sample below. You can also override your selection in the com.android.build.gradle.internal.dsl.ProductFlavor.html block, so each flavor can specify a different matching strategy for a missing dimension. (Tip: you can also use this property if you simply want to change the matching strategy for a dimension that exists in both the app and its dependencies.)

// In the app's build.gradle file.
android {
defaultConfig {
// Specifies a flavor that the plugin should try to use from
// a given dimension. The following tells the plugin that, when encountering
// a dependency that includes a "minApi" dimension, it should select the
// "minApi18" flavor.
missingDimensionStrategy 'minApi', 'minApi18'
// You should specify a missingDimensionStrategy property for each
// dimension that exists in a local dependency but not in your app.
missingDimensionStrategy 'abi', 'x86'
}
flavorDimensions 'tier'
productFlavors {
free {
dimension 'tier'
// You can override the default selection at the product flavor
// level by configuring another missingDimensionStrategy property
// for the "minApi" dimension.
missingDimensionStrategy 'minApi', 'minApi23'
}
paid { }
}
}

resConfig

Added in 7.0.0
Deprecated in 7.0.0
fun resConfig(config: String): Unit

resConfigs

Added in 7.0.0
Deprecated in 7.0.0
fun resConfigs(config: Collection<String>): Unit

resConfigs

Added in 7.0.0
Deprecated in 7.0.0
fun resConfigs(vararg config: String): Unit

setMinSdkVersion

Added in 7.0.0
Deprecated in 7.0.0
fun setMinSdkVersion(minSdkVersion: Int): Unit

setMinSdkVersion

Added in 7.0.0
Deprecated in 7.0.0
fun setMinSdkVersion(minSdkVersion: String?): Unit

setTestFunctionalTest

Added in 7.0.0
Deprecated in 7.0.0
fun setTestFunctionalTest(testFunctionalTest: Boolean): Any?

setTestHandleProfiling

Added in 7.0.0
Deprecated in 7.0.0
fun setTestHandleProfiling(testHandleProfiling: Boolean): Any?

setTestInstrumentationRunnerArguments

Added in 7.0.0
Deprecated in 7.0.0
fun setTestInstrumentationRunnerArguments(
    testInstrumentationRunnerArguments: MutableMap<StringString>
): Any?

testInstrumentationRunnerArgument

Added in 7.0.0
Deprecated in 7.0.0
fun testInstrumentationRunnerArgument(key: String, value: String): Unit

testInstrumentationRunnerArguments

Added in 7.0.0
Deprecated in 7.0.0
fun testInstrumentationRunnerArguments(args: Map<StringString>): Unit

vectorDrawables

Added in 4.2.0
fun vectorDrawables(action: VectorDrawables.() -> Unit): Unit

Configures VectorDrawables.

Public properties

minSdk

Added in 4.2.0
var minSdkInt?

The minimum SDK version. Setting this it will override previous calls of minSdk and minSdkPreview setters. Only one of minSdk and minSdkPreview should be set.

See uses-sdk element documentation.

minSdkPreview

Added in 4.2.0
var minSdkPreviewString?

The minimum SDK version. Setting this it will override previous calls of minSdk and minSdkPreview setters. Only one of minSdk and minSdkPreview should be set.

See uses-sdk element documentation.

renderscriptNdkModeEnabled

Added in 4.2.0
var renderscriptNdkModeEnabledBoolean?

Whether the renderscript code should be compiled to generate C/C++ bindings. True for C/C++ generation, false for Java, null if not specified.

renderscriptSupportModeBlasEnabled

Added in 4.2.0
var renderscriptSupportModeBlasEnabledBoolean?

Whether the renderscript BLAS support lib should be used to make it compatible with older versions of Android.

True if BLAS support lib is enabled, false if not, and null if not specified.

renderscriptSupportModeEnabled

Added in 4.2.0
var renderscriptSupportModeEnabledBoolean?

Whether the renderscript code should be compiled in support mode to make it compatible with older versions of Android.

True if support mode is enabled, false if not, and null if not specified.

renderscriptTargetApi

Added in 4.2.0
var renderscriptTargetApiInt?

The renderscript target api, or null if not specified. This is only the value set on this product flavor.

resourceConfigurations

Added in 4.2.0
Deprecated in 8.9.0-alpha03
val resourceConfigurationsMutableSet<String>

Specifies a list of alternative resources to keep.

For example, if you are using a library that includes language resources (such as AppCompat or Google Play Services), then your APK includes all translated language strings for the messages in those libraries whether the rest of your app is translated to the same languages or not. If you'd like to keep only the languages that your app officially supports, you can specify those languages using the resourceConfigurations property, as shown in the sample below. Any resources for languages not specified are removed.

android {
defaultConfig {
...
// Keeps language resources for only the locales specified below.
resourceConfigurations += ["en", "fr"]
}
}

You can also use this property to filter resources for screen densities. For example, specifying hdpi removes all other screen density resources (such as mdpi, xhdpi, etc) from the final APK.

Note: auto is no longer supported because it created a number of issues with multi-module projects. Instead, you should specify a list of locales that your app supports, as shown in the sample above. Android plugin 3.1.0 and higher ignore the auto argument, and Gradle packages all string resources your app and its dependencies provide.

To learn more, see Remove unused alternative resources.

testApplicationId

Added in 4.2.0
var testApplicationIdString?

Test application ID.

See Set the Application ID

testFunctionalTest

Added in 4.2.0
var testFunctionalTestBoolean?

See instrumentation.

testHandleProfiling

Added in 4.2.0
var testHandleProfilingBoolean?

See instrumentation.

testInstrumentationRunner

Added in 4.2.0
var testInstrumentationRunnerString?

Test instrumentation runner class name.

This is a fully qualified class name of the runner, e.g. android.test.InstrumentationTestRunner

See instrumentation.

testInstrumentationRunnerArguments

Added in 4.2.0
val testInstrumentationRunnerArgumentsMutableMap<StringString>

Test instrumentation runner custom arguments.

e.g. [key: "value"] will give adb shell am instrument -w -e key value com.example...

See instrumentation.

Test runner arguments can also be specified from the command line:

./gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.size=medium
./gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.foo=bar

vectorDrawables

Added in 4.2.0
val vectorDrawablesVectorDrawables

Options to configure the build-time support for vector drawables.

wearAppUnbundled

Added in 4.2.0
var wearAppUnbundledBoolean?

Whether to enable unbundling mode for embedded wear app.

If true, this enables the app to transition from an embedded wear app to one distributed by the play store directly.