BaseFlavor

public interface BaseFlavor extends VariantDimension

Known direct subclasses
ApplicationBaseFlavor
DefaultConfig

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

DynamicFeatureBaseFlavor

Shared properties between DSL objects ProductFlavor and DefaultConfig for dynamic features.

LibraryBaseFlavor
ProductFlavor

Encapsulates all product flavors properties for this project.

TestBaseFlavor
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 methods

abstract Integer

The minimum SDK version.

abstract String

The minimum SDK version.

abstract @NonNull String

The name of the flavor.

abstract Boolean

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

abstract Boolean

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

abstract Boolean

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

abstract Integer

The renderscript target api, or null if not specified.

abstract @NonNull Set<@NonNull String>

Specifies a list of alternative resources to keep.

abstract String

Test application ID.

abstract Boolean

See instrumentation.

abstract Boolean

See instrumentation.

abstract String

Test instrumentation runner class name.

abstract @NonNull Map<@NonNull String, @NonNull String>

Test instrumentation runner custom arguments.

abstract @NonNull VectorDrawables

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

abstract Boolean

Whether to enable unbundling mode for embedded wear app.

abstract void

Copies all properties from the given flavor.

abstract void
minSdkVersion(int minSdkVersion)

This method is deprecated. Replaced by minSdk property

abstract void
minSdkVersion(String minSdkVersion)

This method is deprecated. Replaced by minSdkPreview property

abstract void
missingDimensionStrategy(
    @NonNull String dimension,
    @NonNull String requestedValue
)

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

abstract void
missingDimensionStrategy(
    @NonNull String dimension,
    @NonNull List<@NonNull String> requestedValues
)

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

abstract void
missingDimensionStrategy(
    @NonNull String dimension,
    @NonNull String requestedValues
)

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

abstract void

This method is deprecated. Replaced by resourceConfigurations field

abstract void

This method is deprecated. Replaced by resourceConfigurations field

abstract void

This method is deprecated. Replaced by resourceConfigurations field

abstract void

The minimum SDK version.

abstract void
setMinSdkPreview(String minSdkPreview)

The minimum SDK version.

abstract void
setMinSdkVersion(int minSdkVersion)

This method is deprecated. Replaced by minSdk property

abstract void
setMinSdkVersion(String minSdkVersion)

This method is deprecated. Replaced by minSdkPreview property

abstract void
setRenderscriptNdkModeEnabled(Boolean renderscriptNdkModeEnabled)

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

abstract void
setRenderscriptSupportModeBlasEnabled(
    Boolean renderscriptSupportModeBlasEnabled
)

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

abstract void
setRenderscriptSupportModeEnabled(
    Boolean renderscriptSupportModeEnabled
)

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

abstract void
setRenderscriptTargetApi(Integer renderscriptTargetApi)

The renderscript target api, or null if not specified.

abstract void
setTestApplicationId(String testApplicationId)

Test application ID.

abstract Object
setTestFunctionalTest(boolean testFunctionalTest)

This method is deprecated. Replaced by testFunctionalTest property

abstract void
setTestFunctionalTest(Boolean testFunctionalTest)

See instrumentation.

abstract Object
setTestHandleProfiling(boolean testHandleProfiling)

This method is deprecated. Replaced by testFunctionalTest property

abstract void
setTestHandleProfiling(Boolean testHandleProfiling)

See instrumentation.

abstract void
setTestInstrumentationRunner(String testInstrumentationRunner)

Test instrumentation runner class name.

abstract Object
setTestInstrumentationRunnerArguments(
    @NonNull Map<@NonNull String, @NonNull String> testInstrumentationRunnerArguments
)

This method is deprecated. Replaced by testInstrumentationRunnerArguments property

abstract void
setWearAppUnbundled(Boolean wearAppUnbundled)

Whether to enable unbundling mode for embedded wear app.

abstract void

This method is deprecated. Replaced by testInstrumentationRunnerArguments property

abstract void

This method is deprecated. Replaced by testInstrumentationRunnerArguments property

abstract void

Configures VectorDrawables.

Inherited methods

From com.android.build.api.dsl.VariantDimension
abstract void
addManifestPlaceholders(
    @NonNull Map<@NonNull String, @NonNull Object> manifestPlaceholders
)

Adds manifest placeholders.

abstract void
buildConfigField(
    @NonNull String type,
    @NonNull String name,
    @NonNull String value
)

Adds a new field to the generated BuildConfig class.

abstract void

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

abstract @NonNull ExternalNativeBuildFlags

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

abstract @NonNull JavaCompileOptions

Options for configuring Java compilation.

abstract @NonNull Map<@NonNull String, @NonNull Object>

The manifest placeholders.

abstract File

Text file that specifies additional classes that will be compiled into the main dex file.

abstract File

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

abstract @NonNull Ndk

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

abstract @NonNull Optimization
abstract @NonNull List<@NonNull File>

Specifies the ProGuard configuration files that the plugin should use.

abstract @NonNull Shaders

Options for configuring the shader compiler.

abstract @NonNull List<@NonNull File>

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

abstract void

Options for configuring Java compilation.

abstract void
ndk(@ExtensionFunctionType @NonNull Function1<@NonNull NdkUnit> action)

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

abstract void
abstract @NonNull Object
proguardFile(@NonNull Object proguardFile)

Adds a new ProGuard configuration file.

abstract @NonNull Object

Adds new ProGuard configuration files.

abstract void
resValue(@NonNull String type, @NonNull String name, @NonNull String value)

Adds a new generated resource.

abstract Void
setManifestPlaceholders(
    @NonNull Map<@NonNull String, @NonNull Object> manifestPlaceholders
)

This method is deprecated. Use manifestPlaceholders property instead

abstract void
setMultiDexKeepFile(File multiDexKeepFile)

Text file that specifies additional classes that will be compiled into the main dex file.

abstract void
setMultiDexKeepProguard(File multiDexKeepProguard)

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

abstract @NonNull Object
setProguardFiles(@NonNull Iterable<@NonNull ?> proguardFileIterable)

Replaces the ProGuard configuration files.

abstract void
shaders(
    @ExtensionFunctionType @NonNull Function1<@NonNull ShadersUnit> action
)

Configure the shader compiler options.

abstract @NonNull Object

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

abstract @NonNull Object

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

Public methods

getMinSdk

abstract Integer getMinSdk()

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.

getMinSdkPreview

abstract String getMinSdkPreview()

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.

getName

abstract @NonNull String getName()

The name of the flavor.

getRenderscriptNdkModeEnabled

abstract Boolean getRenderscriptNdkModeEnabled()

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

getRenderscriptSupportModeBlasEnabled

abstract Boolean getRenderscriptSupportModeBlasEnabled()

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.

getRenderscriptSupportModeEnabled

abstract Boolean getRenderscriptSupportModeEnabled()

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.

getRenderscriptTargetApi

abstract Integer getRenderscriptTargetApi()

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

getResourceConfigurations

abstract @NonNull Set<@NonNull StringgetResourceConfigurations()

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.

getTestApplicationId

abstract String getTestApplicationId()

Test application ID.

See Set the Application ID

getTestFunctionalTest

abstract Boolean getTestFunctionalTest()

See instrumentation.

getTestHandleProfiling

abstract Boolean getTestHandleProfiling()

See instrumentation.

getTestInstrumentationRunner

abstract String getTestInstrumentationRunner()

Test instrumentation runner class name.

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

See instrumentation.

getTestInstrumentationRunnerArguments

abstract @NonNull Map<@NonNull String, @NonNull StringgetTestInstrumentationRunnerArguments()

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

getVectorDrawables

abstract @NonNull VectorDrawables getVectorDrawables()

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

getWearAppUnbundled

abstract Boolean getWearAppUnbundled()

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.

initWith

abstract void initWith(@NonNull BaseFlavor that)

Copies all properties from the given flavor.

It can be used like this:

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

minSdkVersion

abstract void minSdkVersion(int minSdkVersion)

minSdkVersion

abstract void minSdkVersion(String minSdkVersion)

missingDimensionStrategy

abstract void missingDimensionStrategy(
    @NonNull String dimension,
    @NonNull String requestedValue
)

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

abstract void missingDimensionStrategy(
    @NonNull String dimension,
    @NonNull List<@NonNull String> requestedValues
)

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

abstract void missingDimensionStrategy(
    @NonNull String dimension,
    @NonNull String requestedValues
)

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

abstract void resConfig(@NonNull String config)

resConfigs

abstract void resConfigs(@NonNull Collection<@NonNull String> config)

resConfigs

abstract void resConfigs(@NonNull String config)

setMinSdk

abstract void setMinSdk(Integer minSdk)

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.

setMinSdkPreview

abstract void setMinSdkPreview(String minSdkPreview)

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.

setMinSdkVersion

abstract void setMinSdkVersion(int minSdkVersion)

setMinSdkVersion

abstract void setMinSdkVersion(String minSdkVersion)

setRenderscriptNdkModeEnabled

abstract void setRenderscriptNdkModeEnabled(Boolean renderscriptNdkModeEnabled)

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

setRenderscriptSupportModeBlasEnabled

abstract void setRenderscriptSupportModeBlasEnabled(
    Boolean renderscriptSupportModeBlasEnabled
)

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.

setRenderscriptSupportModeEnabled

abstract void setRenderscriptSupportModeEnabled(
    Boolean renderscriptSupportModeEnabled
)

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.

setRenderscriptTargetApi

abstract void setRenderscriptTargetApi(Integer renderscriptTargetApi)

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

setTestApplicationId

abstract void setTestApplicationId(String testApplicationId)

Test application ID.

See Set the Application ID

setTestFunctionalTest

abstract Object setTestFunctionalTest(boolean testFunctionalTest)

setTestFunctionalTest

abstract void setTestFunctionalTest(Boolean testFunctionalTest)

See instrumentation.

setTestHandleProfiling

abstract Object setTestHandleProfiling(boolean testHandleProfiling)

setTestHandleProfiling

abstract void setTestHandleProfiling(Boolean testHandleProfiling)

See instrumentation.

setTestInstrumentationRunner

abstract void setTestInstrumentationRunner(String testInstrumentationRunner)

Test instrumentation runner class name.

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

See instrumentation.

setTestInstrumentationRunnerArguments

abstract Object setTestInstrumentationRunnerArguments(
    @NonNull Map<@NonNull String, @NonNull String> testInstrumentationRunnerArguments
)

setWearAppUnbundled

abstract void setWearAppUnbundled(Boolean wearAppUnbundled)

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.

testInstrumentationRunnerArgument

abstract void testInstrumentationRunnerArgument(
    @NonNull String key,
    @NonNull String value
)

testInstrumentationRunnerArguments

abstract void testInstrumentationRunnerArguments(
    @NonNull Map<@NonNull String, @NonNull String> args
)

vectorDrawables

abstract void vectorDrawables(
    @ExtensionFunctionType @NonNull Function1<@NonNull VectorDrawablesUnit> action
)

Configures VectorDrawables.