BuildType

DSL object to configure build types.

Properties

PropertyDescription
applicationIdSuffix

Application id suffix.

consumerProguardFiles

ProGuard rule files to be included in the published AAR.

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.

minifyEnabled

Whether Minify is enabled for this build type.

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.

proguardFiles

Returns ProGuard configuration files to be used.

pseudoLocalesEnabled

Whether to generate pseudo locale in the APK.

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.

useJack
Deprecated

Whether the experimental Jack toolchain should be used.

versionNameSuffix

Version name suffix.

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

No script blocks

Property details

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.

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
}

CoreJavaCompileOptions 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 Manifest merger.

boolean minifyEnabled

Whether Minify is enabled for this build type.

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.

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.

boolean pseudoLocalesEnabled

Whether to generate pseudo locale in the APK.

If enabled, 2 fake pseudo locales (en-XA and ar-XB) will be added to the APK to help test internationalization support in the app.

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 useJack

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

Whether the experimental Jack toolchain should be used.

String versionNameSuffix

Version name suffix.

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

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.