Base DSL object used to configure product flavors.
Property | Description |
applicationId | The application ID. |
applicationIdSuffix | Application id suffix. It is appended to the "base" application id when calculating the final application id for a variant. |
consumerProguardFiles | ProGuard rule files to be included in the published AAR. |
dimension | Specifies the flavor dimension that this product flavor belongs to. |
externalNativeBuild | Encapsulates per-variant CMake and ndk-build configurations for your external native build. |
generatedDensities | Deprecated Deprecated equivalent of |
javaCompileOptions | Options for configuration Java compilation. |
manifestPlaceholders | The manifest placeholders. |
multiDexEnabled | Whether Multi-Dex is enabled for this variant. |
multiDexKeepFile | Text file that specifies additional classes that will be compiled into the main dex file. |
multiDexKeepProguard | 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. |
proguardFiles | Specifies the ProGuard configuration files that the plugin should use. |
signingConfig | Signing config used by this product flavor. |
testApplicationId | Test application ID. |
testFunctionalTest | See instrumentation. |
testHandleProfiling | See instrumentation. |
testInstrumentationRunner | Test instrumentation runner class name. |
testInstrumentationRunnerArguments | Test instrumentation runner custom arguments. |
vectorDrawables | Options to configure the build-time support for |
versionCode | Version code. |
versionName | Version name. |
versionNameSuffix | Version name suffix. It is appended to the "base" version name when calculating the final version name for a variant. |
wearAppUnbundled | Returns 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. |
Method | Description |
buildConfigField(type, name, value) | Adds a new field to the generated BuildConfig class. |
consumerProguardFile(proguardFile) | Adds a proguard rule file to be included in the published AAR. |
consumerProguardFiles(proguardFiles) | Adds proguard rule files to be included in the published AAR. |
maxSdkVersion(maxSdkVersion) | Sets the maximum SDK version to the given value. |
maxSdkVersion(maxSdkVersion) | Sets the maximum SDK version to the given value. |
minSdkVersion(minSdkVersion) | Sets minimum SDK version. |
minSdkVersion(minSdkVersion) | Sets minimum SDK version. |
missingDimensionStrategy(dimension, requestedValue) | Specifies a flavor that the plugin should try to use from a given dimension in a dependency. |
missingDimensionStrategy(dimension, requestedValues) | Specifies a sorted list of flavors that the plugin should try to use from a given dimension in a dependency. |
missingDimensionStrategy(dimension, requestedValues) | Specifies a sorted list of flavors that the plugin should try to use from a given dimension in a dependency. |
proguardFile(proguardFile) | Specifies a ProGuard configuration file that the plugin should use. |
proguardFiles(files) | Specifies ProGuard configuration files that the plugin should use. |
resConfig(config) | Specifies an alternative resource to keep. |
resConfigs(config) | Specifies a list of alternative resources to keep. |
resConfigs(config) | Specifies a list of alternative resources to keep. |
resValue(type, name, value) | Adds a new generated resource. |
setConsumerProguardFiles(proguardFileIterable) | Specifies a proguard rule file to be included in the published AAR. |
setProguardFiles(proguardFileIterable) | Sets the ProGuard configuration files. |
setTestProguardFiles(files) | Specifies proguard rule files to be used when processing test code. |
targetSdkVersion(targetSdkVersion) | Sets the target SDK version to the given value. |
targetSdkVersion(targetSdkVersion) | Sets the target SDK version to the given value. |
testInstrumentationRunnerArgument(key, value) | Adds a custom argument to the test instrumentation runner, e.g: |
testInstrumentationRunnerArguments(args) | Adds custom arguments to the test instrumentation runner, e.g: |
testProguardFile(proguardFile) | Adds a proguard rule file to be used when processing test code. |
testProguardFiles(proguardFiles) | Adds proguard rule files to be used when processing test code. |
Block | Description |
externalNativeBuild | Encapsulates per-variant CMake and ndk-build configurations for your external native build. |
ndk | Encapsulates per-variant configurations for the NDK, such as ABI filters. |
vectorDrawables | Configures |
String
applicationIdSuffix
Application id suffix. It is appended to the "base" application id when calculating the final application id for a variant.
In case there are product flavor dimensions specified, the final application id suffix will contain the suffix from the default product flavor, followed by the suffix from product flavor of the first dimension, second dimension and so on. All of these will have a dot in between e.g. "defaultSuffix.dimension1Suffix.dimensions2Suffix".
ProGuard rule files to be included in the published AAR.
These proguard rule files will then be used by any application project that consumes the AAR (if ProGuard is enabled).
This allows AAR to specify shrinking or obfuscation exclude rules.
This is only valid for Library project. This is ignored in Application project.
String
dimension
Specifies the flavor dimension that this product flavor belongs to.
When configuring product flavors with Android plugin 3.0.0 and higher, you must specify at
least one flavor dimension, using the
flavorDimensions
property, and then assign each flavor to a dimension.
Otherwise, you will get the following build error:
Error:All flavors must now belong to a named flavor dimension.
The flavor 'flavor_name' is not assigned to a flavor dimension.
By default, when you specify only one dimension, all flavors you configure automatically belong to that dimension. If you specify more than one dimension, you need to manually assign each flavor to a dimension, as shown in the sample below:
android { ... // Specifies the flavor dimensions you want to use. The order in which you // list each dimension determines its priority, from highest to lowest, // when Gradle merges variant sources and configurations. You must assign // each product flavor you configure to one of the flavor dimensions. flavorDimensions 'api', 'version' productFlavors { demo { // Assigns this product flavor to the 'version' flavor dimension. dimension 'version' ... } full { dimension 'version' ... } minApi24 { // Assigns this flavor to the 'api' dimension. dimension 'api' minSdkVersion '24' versionNameSuffix "-minApi24" ... } minApi21 { dimension "api" minSdkVersion '21' versionNameSuffix "-minApi21" ... } } }
To learn more about configuring flavor dimensions, read Combine multiple flavors.
ExternalNativeBuildOptions
externalNativeBuild
Encapsulates per-variant CMake and ndk-build configurations for your external native build.
To learn more, see Add C and C++ Code to Your Project.
Note: This property is deprecated and will be removed in a future version of the plugin.
Deprecated equivalent of vectorDrawablesOptions.generatedDensities
.
JavaCompileOptions
javaCompileOptions
Options for configuration Java compilation.
The manifest placeholders.
Boolean
multiDexEnabled
Whether Multi-Dex is enabled for this variant.
File
multiDexKeepFile
Text file that specifies additional classes that will be compiled into the main dex file.
Classes specified in the file are appended to the main dex classes computed using
aapt
.
If set, the file should contain one class per line, in the following format:
com/example/MyClass.class
File
multiDexKeepProguard
Text file with additional ProGuard rules to be used to determine which classes are compiled into the main dex file.
If set, rules from this file are used in combination with the default rules used by the build system.
NdkOptions
ndk
Encapsulates per-variant configurations for the NDK, such as ABI filters.
Specifies the ProGuard configuration files that the plugin should use.
There are two ProGuard rules files that ship with the Android plugin and are used by default:
- proguard-android.txt
- proguard-android-optimize.txt
proguard-android-optimize.txt
is identical to proguard-android.txt
, exccept with optimizations enabled. You can use
getDefaultProguardFile(String filename)
to return the full path of the files.
SigningConfig
signingConfig
Signing config used by this product flavor.
Boolean
testFunctionalTest
See instrumentation.
Boolean
testHandleProfiling
See instrumentation.
String
testInstrumentationRunner
Test instrumentation runner class name.
This is a fully qualified class name of the runner, e.g.
android.test.InstrumentationTestRunner
See instrumentation.
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
VectorDrawablesOptions
vectorDrawables
Options to configure the build-time support for vector
drawables.
String
versionNameSuffix
Version name suffix. It is appended to the "base" version name when calculating the final version name for a variant.
In case there are product flavor dimensions specified, the final version name suffix will contain the suffix from the default product flavor, followed by the suffix from product flavor of the first dimension, second dimension and so on.
Boolean
wearAppUnbundled
Returns 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.
Adds a new field to the generated BuildConfig class.
The field is generated as: <type> <name> = <value>;
This means each of these must have valid Java content. If the type is a String, then the value should include quotes.
void
consumerProguardFile
(Object
proguardFile)
Adds a proguard rule file to be included in the published AAR.
This proguard rule file will then be used by any application project that consume the AAR (if proguard is enabled).
This allows AAR to specify shrinking or obfuscation exclude rules.
This is only valid for Library project. This is ignored in Application project.
void
consumerProguardFiles
(Object
...
proguardFiles)
Object
...Adds proguard rule files to be included in the published AAR.
This proguard rule file will then be used by any application project that consume the AAR (if proguard is enabled).
This allows AAR to specify shrinking or obfuscation exclude rules.
This is only valid for Library project. This is ignored in Application project.
Sets the maximum SDK version to the given value.
Sets the maximum SDK version to the given value.
void
minSdkVersion
(String
minSdkVersion)
Sets minimum SDK version.
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" flavor dimension, 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 defaultConfig
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 productFlavors
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 {} } }
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" flavor dimension, 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 defaultConfig
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 productFlavors
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 sorted list of flavors 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. You can include additional flavor names to provide a // sorted list of fallbacks for the dimension. missingDimensionStrategy 'minApi', 'minApi18', 'minApi23' // You should specify a missingDimensionStrategy property for each // dimension that exists in a local dependency but not in your app. missingDimensionStrategy 'abi', 'x86', 'arm64' } 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', 'minApi18' } paid {} } }
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" flavor dimension, 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 defaultConfig
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 productFlavors
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 sorted list of flavors 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. You can include additional flavor names to provide a // sorted list of fallbacks for the dimension. missingDimensionStrategy 'minApi', 'minApi18', 'minApi23' // You should specify a missingDimensionStrategy property for each // dimension that exists in a local dependency but not in your app. missingDimensionStrategy 'abi', 'x86', 'arm64' } 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', 'minApi18' } paid {} } }
void
proguardFile
(Object
proguardFile)
Specifies a ProGuard configuration file that the plugin should use.
There are two ProGuard rules files that ship with the Android plugin and are used by default:
- proguard-android.txt
- proguard-android-optimize.txt
proguard-android-optimize.txt
is identical to proguard-android.txt
, exccept with optimizations enabled. You can use
getDefaultProguardFile(String filename)
to return the full path of each file.
void
proguardFiles
(Object
...
files)
Object
...Specifies ProGuard configuration files that the plugin should use.
There are two ProGuard rules files that ship with the Android plugin and are used by default:
- proguard-android.txt
- proguard-android-optimize.txt
proguard-android-optimize.txt
is identical to proguard-android.txt
, exccept with optimizations enabled. You can use
getDefaultProguardFile(String filename)
to return the full path of each file.
void
resConfig
(String
config)
Specifies an alternative resource 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 language that your app officially supports,
you can specify those languages using the resConfig
property, as shown in the
sample below. Any resources for languages not specified are removed.
android { defaultConfig { ... // Keeps language resources for only the locale specified below. resConfig "en" } }
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 the locale 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.
void
resConfigs
(String
...
config)
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 resConfigs
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. resConfigs "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.
void
resConfigs
(Collection
<String
>
config)
Collection
<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 resConfigs
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. resConfigs "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.
Adds a new generated resource.
This is equivalent to specifying a resource in res/values.
See Resource Types.
void
setConsumerProguardFiles
(Iterable
<?>
proguardFileIterable)
Iterable
<?>Specifies a proguard rule file to be included in the published AAR.
This proguard rule file will then be used by any application project that consume the AAR (if proguard is enabled).
This allows AAR to specify shrinking or obfuscation exclude rules.
This is only valid for Library project. This is ignored in Application project.
void
setProguardFiles
(Iterable
<?>
proguardFileIterable)
Iterable
<?>Sets the ProGuard configuration files.
There are two ProGuard rules files that ship with the Android plugin and are used by default:
- proguard-android.txt
- proguard-android-optimize.txt
proguard-android-optimize.txt
is identical to proguard-android.txt
, exccept with optimizations enabled. You can use
getDefaultProguardFile(String filename)
to return the full path of the files.
void
setTestProguardFiles
(Iterable
<?>
files)
Iterable
<?>Specifies proguard rule files to be used when processing test code.
Test code needs to be processed to apply the same obfuscation as was done to main code.
Sets the target SDK version to the given value.
void
targetSdkVersion
(String
targetSdkVersion)
Sets the target SDK version to the given value.
Adds a custom argument to the test instrumentation runner, e.g:
testInstrumentationRunnerArgument "size", "medium"
Test runner arguments can also be specified from the command line:
./gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.size=medium ./gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.foo=bar
Adds custom arguments to the test instrumentation runner, e.g:
testInstrumentationRunnerArguments(size: "medium", foo: "bar")
Test runner arguments can also be specified from the command line:
./gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.size=medium ./gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.foo=bar
void
testProguardFile
(Object
proguardFile)
Adds a proguard rule file to be used when processing test code.
Test code needs to be processed to apply the same obfuscation as was done to main code.
void
testProguardFiles
(Object
...
proguardFiles)
Object
...Adds proguard rule files to be used when processing test code.
Test code needs to be processed to apply the same obfuscation as was done to main code.
Encapsulates per-variant CMake and ndk-build configurations for your external native build.
To learn more, see Add C and C++ Code to Your Project.
- Delegates to:
ExternalNativeBuildOptions
fromexternalNativeBuild
Encapsulates per-variant configurations for the NDK, such as ABI filters.
- Delegates to:
NdkOptions
fromndk
Configures VectorDrawablesOptions
.
- Delegates to:
VectorDrawablesOptions
fromvectorDrawables