ProductFlavor

DSL object used to configure product flavors.

Properties

PropertyDescription
applicationId

The application ID.

applicationIdSuffix

Application id suffix.

consumerProguardFiles

ProGuard rule files to be included in the published AAR.

dimension

Name of the dimension this product flavor belongs to.

externalNativeBuild

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

flavorDimension
Deprecated

Name of the dimension this product flavor belongs to. Has been replaced by dimension.

generatedDensities
Deprecated

Deprecated equivalent of vectorDrawablesOptions.generatedDensities.

jackOptions

Options for configuring jack.

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

Returns ProGuard configuration files to be used.

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. e.g. [key: "value"] will give adb shell am instrument -w -e key value com.example...".

useJack
Deprecated

Replaced by the jackOptions.enabled property.

vectorDrawables

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

versionCode

Version code.

versionName

Version name.

versionNameSuffix

Version name suffix.

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.

Methods

MethodDescription
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(targetSdkVersion)

Sets the maximum SDK version to the given value.

maxSdkVersion(targetSdkVersion)

Sets the maximum SDK version to the given value.

minSdkVersion(minSdkVersion)

Sets minimum SDK version.

minSdkVersion(minSdkVersion)

Sets minimum SDK version.

proguardFile(proguardFile)

Adds a new ProGuard configuration file.

proguardFiles(files)

Adds new ProGuard configuration files.

resConfig(config)

Adds a resource configuration filter.

resConfigs(config)

Adds several resource configuration filters.

resConfigs(config)

Adds several resource configuration filters.

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.

Script blocks

BlockDescription
externalNativeBuild

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

jackOptions

Configure Jack options for this product flavor.

ndk

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

vectorDrawables

Configures VectorDrawablesOptions.

Property details

String applicationId

The application ID.

See ApplicationId versus PackageName

String applicationIdSuffix

Application id suffix.

This is appended to the "base" application id when calculating the final application id for a variant.

List<File> consumerProguardFiles

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

Name of the dimension this product flavor belongs to.

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.

String flavorDimension

Note: This property is deprecated and will be removed in a future version of the plugin.

Name of the dimension this product flavor belongs to. Has been replaced by dimension.

Set<String> generatedDensities

Note: This property is deprecated and will be removed in a future version of the plugin.

Deprecated equivalent of vectorDrawablesOptions.generatedDensities.

JackOptions jackOptions

Options for configuring jack.

See Jack and Jill

JavaCompileOptions javaCompileOptions

Options for configuration Java compilation.

Map<String, Object> manifestPlaceholders

The manifest placeholders.

See Manifest merger.

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.

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

List<File> proguardFiles

Returns ProGuard configuration files to be used.

There are 2 default rules files

  • proguard-android.txt
  • proguard-android-optimize.txt

They are located in the SDK. Using getDefaultProguardFile(String filename) will return the full path to the files. They are identical except for enabling optimizations.

See similarly named methods to specify the files.

SigningConfig signingConfig

Signing config used by this product flavor.

String testApplicationId

Test application ID.

See ApplicationId versus PackageName

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.

Map<String, String> testInstrumentationRunnerArguments

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

Boolean useJack

Note: This property is deprecated and will be removed in a future version of the plugin.

Replaced by the jackOptions.enabled property.

VectorDrawablesOptions vectorDrawables

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

Integer versionCode

Version code.

See Versioning Your Application

String versionName

Version name.

See Versioning Your Application

String versionNameSuffix

Version name suffix.

This is appended to the "base" version name when calculating the final version name for a variant.

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.

Method details

void buildConfigField(String type, String name, String value)

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)

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.

void maxSdkVersion(int targetSdkVersion)

Sets the maximum SDK version to the given value.

See uses-sdk element documentation.

void maxSdkVersion(int targetSdkVersion)

Sets the maximum SDK version to the given value.

See uses-sdk element documentation.

void minSdkVersion(int minSdkVersion)

Sets minimum SDK version.

See uses-sdk element documentation.

void minSdkVersion(String minSdkVersion)

Sets minimum SDK version.

See uses-sdk element documentation.

void proguardFile(Object proguardFile)

Adds a new ProGuard configuration file.

proguardFile getDefaultProguardFile('proguard-android.txt')

There are 2 default rules files

  • proguard-android.txt
  • proguard-android-optimize.txt

They are located in the SDK. Using getDefaultProguardFile(String filename) will return the full path to the files. They are identical except for enabling optimizations.

void proguardFiles(Object... files)

Adds new ProGuard configuration files.

There are 2 default rules files

  • proguard-android.txt
  • proguard-android-optimize.txt

They are located in the SDK. Using getDefaultProguardFile(String filename) will return the full path to the files. They are identical except for enabling optimizations.

void resConfig(String config)

Adds a resource configuration filter.

If a qualifier value is passed, then all other resources using a qualifier of the same type but of different value will be ignored from the final packaging of the APK.

For instance, specifying 'hdpi', will ignore all resources using mdpi, xhdpi, etc...

void resConfigs(String... config)

Adds several resource configuration filters.

If a qualifier value is passed, then all other resources using a qualifier of the same type but of different value will be ignored from the final packaging of the APK.

For instance, specifying 'hdpi', will ignore all resources using mdpi, xhdpi, etc...

void resConfigs(Collection<String> config)

Adds several resource configuration filters.

If a qualifier value is passed, then all other resources using a qualifier of the same type but of different value will be ignored from the final packaging of the APK.

For instance, specifying 'hdpi', will ignore all resources using mdpi, xhdpi, etc...

void resValue(String type, String name, String value)

Adds a new generated resource.

This is equivalent to specifying a resource in res/values.

See Resource Types.

void setConsumerProguardFiles(Iterable<?> proguardFileIterable)

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)

Sets the ProGuard configuration files.

There are 2 default rules files

  • proguard-android.txt
  • proguard-android-optimize.txt

They are located in the SDK. Using getDefaultProguardFile(String filename) will return the full path to the files. They are identical except for enabling optimizations.

void setTestProguardFiles(Iterable<?> files)

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.

void targetSdkVersion(int targetSdkVersion)

Sets the target SDK version to the given value.

See uses-sdk element documentation.

void targetSdkVersion(String targetSdkVersion)

Sets the target SDK version to the given value.

See uses-sdk element documentation.

void testInstrumentationRunnerArgument(String key, String 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

void testInstrumentationRunnerArguments(Map<String, String> args)

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)

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.

Script block details

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.

jackOptions { }

Configure Jack options for this product flavor.

See Jack and Jill

Delegates to:
JackOptions from jackOptions

ndk { }

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

Delegates to:
NdkOptions from ndk

vectorDrawables { }

Configures VectorDrawablesOptions.