LibraryExtension

Added in 4.2.0

interface LibraryExtension : CommonExtension, TestedExtension


Extension for the Android Library Gradle Plugin.

This is the android block when the com.android.library plugin is applied.

Only the Android Gradle Plugin should create instances of interfaces in com.android.build.api.dsl.

Summary

Public functions

Unit

Specifies options related to the processing of Android Resources.

Unit

A list of build features that can be enabled or disabled on the Android Project.

Unit

Encapsulates all build type configurations for this project.

Unit

Shortcut extension method to allow easy access to the predefined debug LibraryBuildType

Unit

Specifies defaults for variant properties that the Android plugin applies to all build variants.

Unit

Specifies options for the Android Debug Bridge (ADB), such as APK installation options.

Unit
Unit

Encapsulates all product flavors configurations for this project.

Unit

Customizes publishing build variant artifacts from library module to a Maven repository.

Unit

Shortcut extension method to allow easy access to the predefined release LibraryBuildType

Public properties

MutableCollection<String>?

Aidl files to package in the aar.

LibraryAndroidResources

Specifies options related to the processing of Android Resources.

LibraryBuildFeatures

A list of build features that can be enabled or disabled on the Android Project.

NamedDomainObjectContainer<LibraryBuildType>

Encapsulates all build type configurations for this project.

LibraryDefaultConfig

Specifies defaults for variant properties that the Android plugin applies to all build variants.

LibraryInstallation

Specifies options for the Android Debug Bridge (ADB), such as APK installation options.

NamedDomainObjectContainer<Prefab>

container of Prefab options

PrivacySandbox
NamedDomainObjectContainer<LibraryProductFlavor>

Encapsulates all product flavors configurations for this project.

LibraryPublishing

Customizes publishing build variant artifacts from library module to a Maven repository.

Inherited functions

From com.android.build.api.dsl.CommonExtension
Unit
aaptOptions(action: AaptOptions.() -> Unit)

This function is deprecated. Replaced by

Unit
adbOptions(action: AdbOptions.() -> Unit)

This function is deprecated. Replaced by installation

Unit
buildToolsVersion(buildToolsVersion: String)

This function is deprecated. Replaced by buildToolsVersion property

Unit

Specifies Java compiler options, such as the language level of the Java source code and generated bytecode.

Unit

Configures all aspects regarding compile Sdk version, see CompileSdkSpec for more details.

Unit
compileSdkAddon(vendor: String, name: String, version: Int)

Specify an SDK add-on to compile your project against.

Unit

This function is deprecated. Will be removed in AGP 10.0, replaced by the compileSdk block

Unit

This function is deprecated. Will be removed in AGP 10.0, replaced by the compileSdk block

Unit
Unit
dataBinding(action: DataBinding.() -> Unit)

Specifies options for the Data Binding Library.

Unit

Specifies options for external native build using CMake or ndk-build.

File
Unit

This function is deprecated. Renamed to testCoverage

Unit
lint(action: Lint.() -> Unit)

Specifies options for the lint tool.

Unit

This function is deprecated. Renamed to lint

Unit
packaging(action: Packaging.() -> Unit)

Specifies options and rules that determine which files the Android plugin packages into your APK.

Unit

This function is deprecated. Renamed to packaging

Unit

Encapsulates signing configurations that you can apply to BuildType and ProductFlavor configurations.

Unit

Encapsulates source set configurations for all variants.

Unit
splits(action: Splits.() -> Unit)

Specifies configurations for building multiple APKs or APK splits.

Unit

Configure the gathering of code-coverage from tests.

Unit
testOptions(action: TestOptions.() -> Unit)

Specifies options for how the Android plugin should run local and instrumented tests.

Unit

Includes the specified library to the classpath.

Unit
useLibrary(name: String, required: Boolean)

Includes the specified library to the classpath.

Unit
viewBinding(action: ViewBinding.() -> Unit)

Specifies options for the View Binding Library.

From com.android.build.api.dsl.TestedExtension
Unit

Options to configure the test fixtures.

Inherited properties

From com.android.build.api.dsl.CommonExtension
AaptOptions

This property is deprecated. Replaced by

AdbOptions

This property is deprecated. Replaced by installation

String

Specifies the version of the SDK Build Tools to use when building your project.

CompileOptions

Specifies Java compiler options, such as the language level of the Java source code and generated bytecode.

Int?

Specifies the API level to compile your project against.

Int?

Specifies the SDK Extension level to compile your project against.

Int?

Specify a minor API version for the compile SDK.

String?

Specify a preview API to compile your project against.

ComposeOptions
DataBinding

Specifies options for the Data Binding Library.

MutableMap<StringAny>

Additional per module experimental properties.

ExternalNativeBuild

Specifies options for external native build using CMake or ndk-build.

MutableList<String>

Specifies the names of product flavor dimensions for this project.

JacocoOptions

This property is deprecated. Renamed to testCoverage

Lint

Specifies options for the lint tool.

LintOptions

This property is deprecated. Renamed to lint

String?

The namespace of the generated R and BuildConfig classes.

String?

Requires the specified path to NDK be used.

String

Requires the specified NDK version to be used.

Packaging

Specifies options and rules that determine which files the Android plugin packages into your APK.

Packaging

This property is deprecated. Renamed to packaging

String?

Specifies this project's resource prefix to Android Studio for editor features, such as Lint checks.

SdkComponents
NamedDomainObjectContainer<ApkSigningConfig>

Encapsulates signing configurations that you can apply to [ ] and [ ] configurations.

NamedDomainObjectContainer<AndroidSourceSet>

Encapsulates source set configurations for all variants.

Splits

Specifies configurations for building multiple APKs or APK splits.

TestCoverage

Configure the gathering of code-coverage from tests.

TestOptions

Specifies options for how the Android plugin should run local and instrumented tests.

ViewBinding

Specifies options for the View Binding Library.

From com.android.build.api.dsl.TestedExtension
String

Specifies the build type that the plugin should use to test the module.

TestFixtures

Options to configure the test fixtures.

String?

The namespace used by the android test and unit test components for the generated R and BuildConfig classes.

Public functions

androidResources

Added in 9.0.0-alpha02
fun androidResources(action: LibraryAndroidResources.() -> Unit): Unit

Specifies options related to the processing of Android Resources.

For more information about the properties you can configure in this block, see LibraryAndroidResources.

buildFeatures

Added in 9.0.0-alpha02
fun buildFeatures(action: LibraryBuildFeatures.() -> Unit): Unit

A list of build features that can be enabled or disabled on the Android Project.

buildTypes

Added in 9.0.0-alpha02
fun buildTypes(action: NamedDomainObjectContainer<LibraryBuildType>.() -> Unit): Unit

Encapsulates all build type configurations for this project.

For more information about the properties you can configure in this block, see LibraryBuildType

debug

Added in 9.0.0-alpha02
fun NamedDomainObjectContainer<LibraryBuildType>.debug(action: LibraryBuildType.() -> Unit): Unit

Shortcut extension method to allow easy access to the predefined debug LibraryBuildType

For example:

 android {
buildTypes {
debug {
// ...
}
}
}

defaultConfig

Added in 9.0.0-alpha02
fun defaultConfig(action: LibraryDefaultConfig.() -> Unit): Unit

Specifies defaults for variant properties that the Android plugin applies to all build variants.

You can override any defaultConfig property when configuring product flavors

For more information about the properties you can configure in this block, see LibraryDefaultConfig.

installation

Added in 9.0.0-alpha02
fun installation(action: LibraryInstallation.() -> Unit): Unit

Specifies options for the Android Debug Bridge (ADB), such as APK installation options.

For more information about the properties you can configure in this block, see AdbOptions.

privacySandbox

Added in 8.3.1
fun privacySandbox(action: PrivacySandbox.() -> Unit): Unit

productFlavors

Added in 9.0.0-alpha02
fun productFlavors(action: NamedDomainObjectContainer<LibraryProductFlavor>.() -> Unit): Unit

Encapsulates all product flavors configurations for this project.

For more information about the properties you can configure in this block, see ProductFlavor

publishing

Added in 7.1.0
fun publishing(action: LibraryPublishing.() -> Unit): Unit

Customizes publishing build variant artifacts from library module to a Maven repository.

For more information about the properties you can configure in this block, see LibraryPublishing

release

Added in 9.0.0-alpha02
fun NamedDomainObjectContainer<LibraryBuildType>.release(
    action: LibraryBuildType.() -> Unit
): Unit

Shortcut extension method to allow easy access to the predefined release LibraryBuildType

For example:

 android {
buildTypes {
release {
// ...
}
}
}

Public properties

aidlPackagedList

Added in 4.2.0
val aidlPackagedListMutableCollection<String>?

Aidl files to package in the aar.

androidResources

val androidResourcesLibraryAndroidResources

Specifies options related to the processing of Android Resources.

For more information about the properties you can configure in this block, see LibraryAndroidResources.

buildFeatures

val buildFeaturesLibraryBuildFeatures

A list of build features that can be enabled or disabled on the Android Project.

buildTypes

val buildTypesNamedDomainObjectContainer<LibraryBuildType>

Encapsulates all build type configurations for this project.

Unlike using LibraryProductFlavor to create different versions of your project that you expect to co-exist on a single device, build types determine how Gradle builds and packages each version of your project. Developers typically use them to configure projects for various stages of a development lifecycle. For example, when creating a new project from Android Studio, the Android plugin configures a 'debug' and 'release' build type for you. You can then combine build types with product flavors to create build variants.

See also
BuildType

defaultConfig

val defaultConfigLibraryDefaultConfig

Specifies defaults for variant properties that the Android plugin applies to all build variants.

You can override any defaultConfig property when configuring product flavors

For more information about the properties you can configure in this block, see LibraryDefaultConfig.

installation

val installationLibraryInstallation

Specifies options for the Android Debug Bridge (ADB), such as APK installation options.

For more information about the properties you can configure in this block, see AdbOptions.

prefab

Added in 4.2.0
val prefabNamedDomainObjectContainer<Prefab>

container of Prefab options

privacySandbox

Added in 8.3.1
val privacySandboxPrivacySandbox

productFlavors

val productFlavorsNamedDomainObjectContainer<LibraryProductFlavor>

Encapsulates all product flavors configurations for this project.

Product flavors represent different versions of your project that you expect to co-exist on a single device, the Google Play store, or repository. For example, you can configure 'demo' and 'full' product flavors for your app, and each of those flavors can specify different features, device requirements, resources, and application ID's--while sharing common source code and resources. So, product flavors allow you to output different versions of your project by simply changing only the components and settings that are different between them.

Configuring product flavors is similar to configuring build types: add them to the productFlavors block of your project's build.gradle file and configure the settings you want. Product flavors support the same properties as the defaultConfig block--this is because defaultConfig defines an object that the plugin uses as the base configuration for all other flavors. Each flavor you configure can then override any of the default values in defaultConfig, such as the applicationId.

When using Android plugin 3.0.0 and higher, each flavor must belong to a com.android.build.gradle.BaseExtension.html#com.android.build.gradle.BaseExtension:flavorDimensions(java.lang.String[]) value. By default, when you specify only one dimension, all flavors you configure belong to that dimension. If you specify more than one flavor dimension, you need to manually assign each flavor to a dimension. To learn more, read Use Flavor Dimensions for variant-aware dependency management.

When you configure product flavors, the Android plugin automatically combines them with your LibraryBuildType configurations to create build variants. If the plugin creates certain build variants that you don't want, you can filter variants.

publishing

Added in 7.1.0
val publishingLibraryPublishing

Customizes publishing build variant artifacts from library module to a Maven repository.

For more information about the properties you can configure in this block, see LibraryPublishing