BuildType

DSL object to configure build types.

Properties

PropertyDescription
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.

crunchPngs

Whether to crunch PNGs.

debuggable

Whether this build type should generate a debuggable apk.

embedMicroApp

Whether a linked Android Wear app should be embedded in variant using this build type.

javaCompileOptions

Options for configuration Java compilation.

jniDebuggable

Whether this build type is configured to generate an APK with debuggable native code.

manifestPlaceholders

The manifest placeholders.

matchingFallbacks

Specifies a sorted list of build types that the plugin should try to use when a direct variant match with a local module dependency is not possible.

minifyEnabled

Whether removal of unused java code is enabled.

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.

name

Name of this build type.

postprocessing
Incubating

This DSL is incubating and subject to change.

proguardFiles

Specifies the ProGuard configuration files that the plugin should use.

pseudoLocalesEnabled

Specifies whether the plugin should generate resources for pseudolocales.

renderscriptDebuggable

Whether the build type is configured to generate an apk with debuggable RenderScript code.

renderscriptOptimLevel

Optimization level to use by the renderscript compiler.

shrinkResources

Whether shrinking of unused resources is enabled. Default is false;

signingConfig

The signing configuration.

testCoverageEnabled

Whether test coverage is enabled for this build type.

useProguard

Specifies whether to always use ProGuard for code and resource shrinking.

versionNameSuffix

Version name suffix. It is appended to the "base" version name when calculating the final version name for a variant.

zipAlignEnabled

Whether zipalign is enabled for this build type.

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.

externalNativeBuild(action)

Configure native build options.

initWith(that)

Copies all properties from the given build type.

proguardFile(proguardFile)

Adds a new ProGuard configuration file.

proguardFiles(files)

Adds new ProGuard configuration files.

resValue(type, name, value)

Adds a new generated resource.

resValue(type, name, value)

Adds a new generated resource.

setProguardFiles(proguardFileIterable)

Sets the ProGuard configuration files.

Script blocks

BlockDescription
postprocessing
Incubating

This DSL is incubating and subject to change.

Property details

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".

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.

Boolean crunchPngs

Whether to crunch PNGs.

Setting this property to true reduces of PNG resources that are not already optimally compressed. However, this process increases build times.

PNG crunching is enabled by default in the release build type and disabled by default in the debug build type.

boolean debuggable

Whether this build type should generate a debuggable apk.

boolean embedMicroApp

Whether a linked Android Wear app should be embedded in variant using this build type.

Wear apps can be linked with the following code:

dependencies {
  freeWearApp project(:wear:free') // applies to variant using the free flavor
  wearApp project(':wear:base') // applies to all other variants
}

com.android.build.gradle.api.JavaCompileOptions javaCompileOptions

Options for configuration Java compilation.

boolean jniDebuggable

Whether this build type is configured to generate an APK with debuggable native code.

Map<String, Object> manifestPlaceholders

The manifest placeholders.

See Inject Build Variables into the Manifest.

List<String> matchingFallbacks

Specifies a sorted list of build types that the plugin should try to use when a direct variant match with a local module dependency is not possible.

Android plugin 3.0.0 and higher try to match each variant of your module with the same one from its dependencies. For example, 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 your app includes build types that a dependency does not. For example, consider if your app includes a "stage" build type, but a dependency includes only a "debug" and "release" build type. When the plugin tries to build the "stage" version of your app, it won't know which version of the dependency to use, 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 situation, you can use matchingFallbacks to specify alternative matches for the app's "stage" build type, as shown below:

// In the app's build.gradle file.
android {
    buildTypes {
        release {
            // Because the dependency already includes a "release" build type,
            // you don't need to provide a list of fallbacks here.
        }
        stage {
            // Specifies a sorted list of fallback build types that the
            // plugin should try to use when a dependency does not include a
            // "stage" build type. You may specify as many fallbacks as you
            // like, and the plugin selects the first build type that's
            // available in the dependency.
            matchingFallbacks = ['debug', 'qa', 'release']
        }
    }
}

Note that there is no issue when a library dependency includes a build type that your app does not. That's because the plugin simply never requests that build type from the dependency.

boolean minifyEnabled

Whether removal of unused java code is enabled.

Default is false.

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.

String name

Name of this build type.

PostprocessingOptions postprocessing

Note: This property is incubating and may change in a future version of the plugin.

This DSL is incubating and subject to change.

List<File> proguardFiles

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.

boolean pseudoLocalesEnabled

Specifies whether the plugin should generate resources for pseudolocales.

A pseudolocale is a locale that simulates characteristics of languages that cause UI, layout, and other translation-related problems when an app is localized. Pseudolocales can aid your development workflow because you can test and make adjustments to your UI before you finalize text for translation.

When you set this property to true as shown below, the plugin generates resources for the following pseudo locales and makes them available in your connected device's language preferences: en-XA and ar-XB.

android {
    buildTypes {
        debug {
            pseudoLocalesEnabled true
        }
    }
}

When you build your app, the plugin includes the pseudolocale resources in your APK. If you notice that your APK does not include those locale resources, make sure your build configuration isn't limiting which locale resources are packaged with your APK, such as using the resConfigs property to remove unused locale resources.

To learn more, read Test Your App with Pseudolocales.

boolean renderscriptDebuggable

Whether the build type is configured to generate an apk with debuggable RenderScript code.

int renderscriptOptimLevel

Optimization level to use by the renderscript compiler.

boolean shrinkResources

Whether shrinking of unused resources is enabled. Default is false;

SigningConfig signingConfig

The signing configuration.

boolean testCoverageEnabled

Whether test coverage is enabled for this build type.

If enabled this uses Jacoco to capture coverage and creates a report in the build directory.

The version of Jacoco can be configured with:

android {
  jacoco {
    version = '0.6.2.201302030002'
  }
}

Boolean useProguard

Specifies whether to always use ProGuard for code and resource shrinking.

By default, when you enable code shrinking by setting minifyEnabled to true, the Android plugin uses ProGuard. However while deploying your app using Android Studio's Instant Run feature, which doesn't support ProGuard, the plugin switches to using a custom experimental code shrinker.

If you experience issues using the experimental code shrinker, you can disable code shrinking while using Instant Run by setting this property to true.

To learn more, read Shrink Your Code and Resources.

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 zipAlignEnabled

Whether zipalign is enabled for this build type.

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.

BuildType 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.

BuildType 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.

Configure native build options.

DefaultBuildType initWith(BuildType that)

Copies all properties from the given build type.

It can be used like this:

android.buildTypes {
    customBuildType {
        initWith debug
            // customize...
        }
}

BuildType 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.

BuildType 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 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 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.

BuildType 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.

Script block details

postprocessing { }

Note: This script block is incubating and may change in a future version of the plugin.

This DSL is incubating and subject to change.

Delegates to:
PostprocessingOptions from postprocessing