Stay organized with collections
Save and categorize content based on your preferences.
LibraryBuildType
interface LibraryBuildType : BuildType, LibraryVariantDimension
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.
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, while the release build type is not
debuggable and can be configured to, for example shrink and obfuscate your library for
distribution.
See
configuring build types
for more information.
Summary
Inherited functions
|
From class LibraryVariantDimension
Unit |
aarMetadata(action: AarMetadata.() -> Unit)
Options for configuring AAR metadata.
|
Unit |
aarMetadata(action: Action<AarMetadata>)
Options for configuring AAR metadata.
|
Any |
consumerProguardFile(proguardFile: Any)
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.
This method has a return value for legacy reasons.
|
Any |
consumerProguardFiles(vararg proguardFiles: Any)
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.
This method has a return value for legacy reasons.
|
|
From class VariantDimension
Unit |
addManifestPlaceholders(manifestPlaceholders: Map<String, Any>)
Adds manifest placeholders.
See
Inject Build Variables into the Manifest.
|
Unit |
addManifestPlaceholders(manifestPlaceholders: Map<String, Any>)
Adds manifest placeholders.
See
Inject Build Variables into the Manifest.
|
Unit |
buildConfigField(type: String, name: String, value: String)
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.
|
Unit |
buildConfigField(type: String, name: String, value: String)
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.
|
Unit |
externalNativeBuild(action: ExternalNativeBuildOptions.() -> Unit)
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.
|
Unit |
externalNativeBuild(action: ExternalNativeBuildOptions.() -> Unit)
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.
|
Unit |
javaCompileOptions(action: JavaCompileOptions.() -> Unit)
Options for configuring Java compilation.
|
Unit |
javaCompileOptions(action: JavaCompileOptions.() -> Unit)
Options for configuring Java compilation.
|
Unit |
ndk(action: Ndk.() -> Unit)
Encapsulates per-variant configurations for the NDK, such as ABI filters.
|
Unit |
ndk(action: Ndk.() -> Unit)
Encapsulates per-variant configurations for the NDK, such as ABI filters.
|
Any |
proguardFile(proguardFile: Any)
Adds a new ProGuard configuration file.
proguardFile getDefaultProguardFile('proguard-android.txt')
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 ,
except with optimizations enabled. You can use getDefaultProguardFileString
to return the full path of the files.
This method has a return value for legacy reasons.
|
Any |
proguardFile(proguardFile: Any)
Adds a new ProGuard configuration file.
proguardFile getDefaultProguardFile('proguard-android.txt')
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 ,
except with optimizations enabled. You can use getDefaultProguardFileString
to return the full path of the files.
This method has a return value for legacy reasons.
|
Any |
proguardFiles(vararg files: Any)
Adds new ProGuard configuration files.
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 ,
except with optimizations enabled. You can use getDefaultProguardFileString
to return the full path of the files.
This method has a return value for legacy reasons.
|
Any |
proguardFiles(vararg files: Any)
Adds new ProGuard configuration files.
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 ,
except with optimizations enabled. You can use getDefaultProguardFileString
to return the full path of the files.
This method has a return value for legacy reasons.
|
Unit |
resValue(type: String, name: String, value: String)
Adds a new generated resource.
This is equivalent to specifying a resource in res/values.
See Resource Types.
|
Unit |
resValue(type: String, name: String, value: String)
Adds a new generated resource.
This is equivalent to specifying a resource in res/values.
See Resource Types.
|
Void? |
setManifestPlaceholders(manifestPlaceholders: Map<String, Any>)
|
Void? |
setManifestPlaceholders(manifestPlaceholders: Map<String, Any>)
|
Any |
setProguardFiles(proguardFileIterable: Iterable<*>)
Replaces the ProGuard configuration files.
This method has a return value for legacy reasons.
|
Any |
setProguardFiles(proguardFileIterable: Iterable<*>)
Replaces the ProGuard configuration files.
This method has a return value for legacy reasons.
|
Unit |
shaders(action: Shaders.() -> Unit)
Configure the shader compiler options.
|
Unit |
shaders(action: Shaders.() -> Unit)
Configure the shader compiler options.
|
Any |
testProguardFile(proguardFile: Any)
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.
This method has a return value for legacy reasons.
|
Any |
testProguardFile(proguardFile: Any)
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.
This method has a return value for legacy reasons.
|
Any |
testProguardFiles(vararg proguardFiles: Any)
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.
This method has a return value for legacy reasons.
|
Any |
testProguardFiles(vararg proguardFiles: Any)
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.
This method has a return value for legacy reasons.
|
|
|
Properties
|
abstract Boolean |
Whether this build type should be selected in Studio by default
|
Inherited properties
|
From class LibraryVariantDimension
AarMetadata |
aarMetadata
Options for configuring AAR metadata.
|
MutableList<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? |
multiDexEnabled
Returns whether multi-dex is enabled.
This can be null if the flag is not set, in which case the default value is used.
|
ApkSigningConfig? |
signingConfig
The associated signing config or null if none are set on the variant dimension.
|
|
From class VariantDimension
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.
|
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.
|
JavaCompileOptions |
javaCompileOptions
Options for configuring Java compilation.
|
JavaCompileOptions |
javaCompileOptions
Options for configuring Java compilation.
|
MutableMap<String, Any> |
manifestPlaceholders
The manifest placeholders.
See
Inject Build Variables into the Manifest.
|
MutableMap<String, Any> |
manifestPlaceholders
The manifest placeholders.
See
Inject Build Variables into the Manifest.
|
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? |
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.
|
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.
|
Ndk |
ndk
Encapsulates per-variant configurations for the NDK, such as ABI filters.
|
Ndk |
ndk
Encapsulates per-variant configurations for the NDK, such as ABI filters.
|
MutableList<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 ,
except with optimizations enabled. You can use getDefaultProguardFileString
to return the full path of the files.
|
MutableList<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 ,
except with optimizations enabled. You can use getDefaultProguardFileString
to return the full path of the files.
|
Shaders |
shaders
Options for configuring the shader compiler.
|
Shaders |
shaders
Options for configuring the shader compiler.
|
MutableList<File> |
testProguardFiles
The collection of 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.
|
MutableList<File> |
testProguardFiles
The collection of 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.
|
|
From class BuildType
Boolean |
isJniDebuggable
Whether this build type is configured to generate an APK with debuggable native code.
|
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.
|
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.
|
Boolean |
isRenderscriptDebuggable
Whether the build type is configured to generate an apk with debuggable RenderScript code.
|
Boolean |
isShrinkResources
Specifies whether to enable shrinking resources for this build type.
To learn more, read
Shrink Your Code and Resources.
|
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'
}
}
|
Boolean |
isZipAlignEnabled
|
MutableList<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 adependency 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.
|
PostProcessing |
postprocessing
|
Int |
renderscriptOptimLevel
Optimization level to use by the renderscript compiler.
|
|
Properties
isDefault
abstract var isDefault: Boolean
Whether this build type should be selected in Studio by default
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[]]