The configuration of a product flavor. This is also used to describe the default configuration of all builds, even those that do not contain any flavors.
Property | Description |
consumerProguardFiles | ProGuard rule files to be included in the published AAR. |
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. |
proguardFiles | Specifies the ProGuard configuration files that the plugin should use. |
Method | Description |
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. |
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.
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.
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.
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 {} } }