BuildType

public interface BuildType extends Named, VariantDimension, ExtensionAware

Known direct subclasses
ApplicationBuildType

Build types define certain properties that Gradle uses when building and packaging your app, and are typically configured for different stages of your development lifecycle.

DynamicFeatureBuildType

Build types define certain properties that Gradle uses when building and packaging your app, and are typically configured for different stages of your development lifecycle.

LibraryBuildType

Build types define certain properties that Gradle uses when building and packaging your library, and are typically configured for different stages of your development lifecycle.

TestBuildType

Build types define certain properties that Gradle uses when building and packaging your library, and are typically configured for different stages of your development lifecycle.


Build types define certain properties that Gradle uses when building and packaging your app, and are typically configured for different stages of your development lifecycle.

There are two build types defined by default, debug and release, and you can customize them and create additional build types.

The default debug build type enables debug options and signs the APK with the debug key, while the release build type is not debuggable and can be configured to shrink, obfuscate, and sign your APK with a release key for distribution.

See configuring build types for more information.

Summary

Public methods

abstract boolean

Specifies code coverage is enabled for module tests of type AndroidTest.

abstract boolean

Specifies unit test code coverage data collection by configuring the JacocoPlugin.

abstract @NonNull List<@NonNull String>

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.

abstract @NonNull PostProcessing
abstract int

Optimization level to use by the renderscript compiler.

abstract void

Copies all properties from the given build type.

abstract boolean

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

abstract boolean

Specifies whether to enable code shrinking for this build type.

abstract boolean

Specifies whether the plugin should generate resources for pseudolocales.

abstract boolean

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

abstract boolean

Specifies whether to enable shrinking resources for this build type.

abstract boolean

Whether test coverage is enabled for this build type.

abstract boolean
abstract void
abstract void
setEnableAndroidTestCoverage(boolean enableAndroidTestCoverage)

Specifies code coverage is enabled for module tests of type AndroidTest.

abstract void
setEnableUnitTestCoverage(boolean enableUnitTestCoverage)

Specifies unit test code coverage data collection by configuring the JacocoPlugin.

abstract void
setJniDebuggable(boolean isJniDebuggable)

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

abstract void

This method is deprecated. Replaced with property matchingFallbacks

abstract void

This method is deprecated. Replaced with property matchingFallbacks

abstract void
setMinifyEnabled(boolean isMinifyEnabled)

Specifies whether to enable code shrinking for this build type.

abstract void
setPseudoLocalesEnabled(boolean isPseudoLocalesEnabled)

Specifies whether the plugin should generate resources for pseudolocales.

abstract void
setRenderscriptDebuggable(boolean isRenderscriptDebuggable)

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

abstract void
setRenderscriptOptimLevel(int renderscriptOptimLevel)

Optimization level to use by the renderscript compiler.

abstract void
setShrinkResources(boolean isShrinkResources)

Specifies whether to enable shrinking resources for this build type.

abstract void
setTestCoverageEnabled(boolean isTestCoverageEnabled)

Whether test coverage is enabled for this build type.

abstract void
setZipAlignEnabled(boolean isZipAlignEnabled)

Inherited methods

From org.gradle.api.plugins.ExtensionAware
From org.gradle.api.Named
abstract @NonNull String
From com.android.build.api.dsl.VariantDimension
abstract void
addManifestPlaceholders(
    @NonNull Map<@NonNull String, @NonNull Object> manifestPlaceholders
)

Adds manifest placeholders.

abstract void
buildConfigField(
    @NonNull String type,
    @NonNull String name,
    @NonNull String value
)

Adds a new field to the generated BuildConfig class.

abstract void

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

abstract @NonNull ExternalNativeBuildFlags

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

abstract @NonNull JavaCompileOptions

Options for configuring Java compilation.

abstract @NonNull Map<@NonNull String, @NonNull Object>

The manifest placeholders.

abstract File

Text file that specifies additional classes that will be compiled into the main dex file.

abstract File

Text file with additional ProGuard rules to be used to determine which classes are compiled into the main dex file.

abstract @NonNull Ndk

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

abstract @NonNull Optimization
abstract @NonNull List<@NonNull File>

Specifies the ProGuard configuration files that the plugin should use.

abstract @NonNull Shaders

Options for configuring the shader compiler.

abstract @NonNull List<@NonNull File>

The collection of proguard rule files to be used when processing test code.

abstract void

Options for configuring Java compilation.

abstract void
ndk(@ExtensionFunctionType @NonNull Function1<@NonNull NdkUnit> action)

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

abstract void
abstract @NonNull Object
proguardFile(@NonNull Object proguardFile)

Adds a new ProGuard configuration file.

abstract @NonNull Object

Adds new ProGuard configuration files.

abstract void
resValue(@NonNull String type, @NonNull String name, @NonNull String value)

Adds a new generated resource.

abstract Void
setManifestPlaceholders(
    @NonNull Map<@NonNull String, @NonNull Object> manifestPlaceholders
)

This method is deprecated. Use manifestPlaceholders property instead

abstract void
setMultiDexKeepFile(File multiDexKeepFile)

Text file that specifies additional classes that will be compiled into the main dex file.

abstract void
setMultiDexKeepProguard(File multiDexKeepProguard)

Text file with additional ProGuard rules to be used to determine which classes are compiled into the main dex file.

abstract @NonNull Object
setProguardFiles(@NonNull Iterable<@NonNull ?> proguardFileIterable)

Replaces the ProGuard configuration files.

abstract void
shaders(
    @ExtensionFunctionType @NonNull Function1<@NonNull ShadersUnit> action
)

Configure the shader compiler options.

abstract @NonNull Object

Adds a proguard rule file to be used when processing test code.

abstract @NonNull Object

Adds proguard rule files to be used when processing test code.

Public methods

getEnableAndroidTestCoverage

abstract boolean getEnableAndroidTestCoverage()

Specifies code coverage is enabled for module tests of type AndroidTest.

If enabled, prepares module class files for code coverage collection such as instrumenting dependent library classes and module classes. This allows for code coverage reports to be generated.

getEnableUnitTestCoverage

abstract boolean getEnableUnitTestCoverage()

Specifies unit test code coverage data collection by configuring the JacocoPlugin.

When enabled, the Jacoco plugin is applied and coverage data is collected by the Jacoco plugin. This can avoid unwanted build time instrumentation required to collect coverage data from other test types such as connected tests.

getMatchingFallbacks

abstract @NonNull List<@NonNull StringgetMatchingFallbacks()

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.

Returns
@NonNull List<@NonNull String>

the names of product flavors to use, in descending priority order

getPostprocessing

@Incubating
abstract @NonNull PostProcessing getPostprocessing()

getRenderscriptOptimLevel

abstract int getRenderscriptOptimLevel()

Optimization level to use by the renderscript compiler. RenderScript APIs are deprecated starting in Android 12. For more information about how to migrate, see https://developer.android.com/guide/topics/renderscript/migrate

initWith

abstract void initWith(@NonNull BuildType that)

Copies all properties from the given build type.

It can be used like this:

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

isJniDebuggable

abstract boolean isJniDebuggable()

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

isMinifyEnabled

abstract boolean isMinifyEnabled()

Specifies whether to enable code shrinking for this build type.

By default, when you enable code shrinking by setting this property to true, the Android plugin uses ProGuard.

To learn more, read Shrink Your Code and Resources.

isPseudoLocalesEnabled

abstract boolean isPseudoLocalesEnabled()

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 resourceConfigurations property to remove unused locale resources.

To learn more, read Test Your App with Pseudolocales.

isRenderscriptDebuggable

abstract boolean isRenderscriptDebuggable()

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

RenderScript APIs are deprecated starting in Android 12. For more information about how to migrate, see https://developer.android.com/guide/topics/renderscript/migrate

isShrinkResources

abstract boolean isShrinkResources()

Specifies whether to enable shrinking resources for this build type.

To learn more, read Shrink Your Code and Resources.

isTestCoverageEnabled

abstract boolean isTestCoverageEnabled()

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 {
testCoverage {
jacocoVersion = '0.6.2.201302030002'
}
}

isTestCoverageEnabled is deprecated. Use enableUnitTestCoverage and enableAndroidTestCoverage instead which allow you to enable coverage separately for unit and instrumentation tests.

isZipAlignEnabled

abstract boolean isZipAlignEnabled()

postprocessing

@Incubating
abstract void postprocessing(
    @ExtensionFunctionType @NonNull Function1<@NonNull PostProcessingUnit> action
)

setEnableAndroidTestCoverage

abstract void setEnableAndroidTestCoverage(boolean enableAndroidTestCoverage)

Specifies code coverage is enabled for module tests of type AndroidTest.

If enabled, prepares module class files for code coverage collection such as instrumenting dependent library classes and module classes. This allows for code coverage reports to be generated.

setEnableUnitTestCoverage

abstract void setEnableUnitTestCoverage(boolean enableUnitTestCoverage)

Specifies unit test code coverage data collection by configuring the JacocoPlugin.

When enabled, the Jacoco plugin is applied and coverage data is collected by the Jacoco plugin. This can avoid unwanted build time instrumentation required to collect coverage data from other test types such as connected tests.

setJniDebuggable

abstract void setJniDebuggable(boolean isJniDebuggable)

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

setMatchingFallbacks

abstract void setMatchingFallbacks(@NonNull List<@NonNull String> fallbacks)

setMatchingFallbacks

abstract void setMatchingFallbacks(@NonNull String fallbacks)

setMinifyEnabled

abstract void setMinifyEnabled(boolean isMinifyEnabled)

Specifies whether to enable code shrinking for this build type.

By default, when you enable code shrinking by setting this property to true, the Android plugin uses ProGuard.

To learn more, read Shrink Your Code and Resources.

setPseudoLocalesEnabled

abstract void setPseudoLocalesEnabled(boolean isPseudoLocalesEnabled)

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 resourceConfigurations property to remove unused locale resources.

To learn more, read Test Your App with Pseudolocales.

setRenderscriptDebuggable

abstract void setRenderscriptDebuggable(boolean isRenderscriptDebuggable)

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

RenderScript APIs are deprecated starting in Android 12. For more information about how to migrate, see https://developer.android.com/guide/topics/renderscript/migrate

setRenderscriptOptimLevel

abstract void setRenderscriptOptimLevel(int renderscriptOptimLevel)

Optimization level to use by the renderscript compiler. RenderScript APIs are deprecated starting in Android 12. For more information about how to migrate, see https://developer.android.com/guide/topics/renderscript/migrate

setShrinkResources

abstract void setShrinkResources(boolean isShrinkResources)

Specifies whether to enable shrinking resources for this build type.

To learn more, read Shrink Your Code and Resources.

setTestCoverageEnabled

abstract void setTestCoverageEnabled(boolean isTestCoverageEnabled)

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 {
testCoverage {
jacocoVersion = '0.6.2.201302030002'
}
}

isTestCoverageEnabled is deprecated. Use enableUnitTestCoverage and enableAndroidTestCoverage instead which allow you to enable coverage separately for unit and instrumentation tests.

setZipAlignEnabled

abstract void setZipAlignEnabled(boolean isZipAlignEnabled)