TestExtension

Added in 4.2.0

interface TestExtension : CommonExtension


Extension for the Android Test Gradle Plugin.

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

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

Summary

Public functions

Unit
aaptOptions(action: AaptOptions.() -> Unit)

This function is deprecated. Replaced by

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

This function is deprecated. Replaced by installation

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

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

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

Specifies options for the Data Binding Library.

Unit

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

Unit

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

Unit

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

Unit

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

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
Unit

Encapsulates all product flavors configurations for this project.

Unit

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

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
viewBinding(action: ViewBinding.() -> Unit)

Specifies options for the View Binding Library.

Public properties

AaptOptions

This property is deprecated. Replaced by

AdbOptions

This property is deprecated. Replaced by installation

TestAndroidResources

Specifies options related to the processing of Android Resources.

TestBuildFeatures

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

NamedDomainObjectContainer<TestBuildType>

Encapsulates all build type configurations for this project.

CompileOptions

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

ComposeOptions
DataBinding

Specifies options for the Data Binding Library.

TestDefaultConfig

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

ExternalNativeBuild

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

TestInstallation

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

JacocoOptions

This property is deprecated. Renamed to testCoverage

Lint

Specifies options for the lint tool.

LintOptions

This property is deprecated. Renamed to lint

Packaging

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

Packaging

This property is deprecated. Renamed to packaging

PrivacySandbox

Options related to the consumption of privacy sandbox libraries

NamedDomainObjectContainer<TestProductFlavor>

Encapsulates all product flavors configurations for this project.

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.

String?

The Gradle path of the project that this test project tests.

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.

Inherited functions

From com.android.build.api.dsl.CommonExtension
Unit
buildToolsVersion(buildToolsVersion: String)

This function is deprecated. Replaced by buildToolsVersion property

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

File
Unit

Includes the specified library to the classpath.

Unit
useLibrary(name: String, required: Boolean)

Includes the specified library to the classpath.

From org.gradle.api.plugins.ExtensionAware

Inherited properties

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

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

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.

Boolean

Enables the compilation of Kotlin sources.

MutableMap<StringAny>

Additional per module experimental properties.

MutableList<String>

Specifies the names of product flavor dimensions for this project.

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.

String?

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

SdkComponents

Public functions

aaptOptions

fun aaptOptions(action: AaptOptions.() -> Unit): Unit

Specifies options for the Android Asset Packaging Tool (AAPT).

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

adbOptions

fun adbOptions(action: AdbOptions.() -> 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.

androidResources

Added in 9.0.0-alpha14
fun androidResources(action: TestAndroidResources.() -> Unit): Unit

Specifies options related to the processing of Android Resources.

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

buildFeatures

Added in 9.0.0-alpha14
fun buildFeatures(action: TestBuildFeatures.() -> Unit): Unit

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

buildTypes

Added in 9.0.0-alpha14
fun buildTypes(action: NamedDomainObjectContainer<TestBuildType>.() -> Unit): Unit

Encapsulates all build type configurations for this project.

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

compileOptions

fun compileOptions(action: CompileOptions.() -> Unit): Unit

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

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

composeOptions

fun composeOptions(action: ComposeOptions.() -> Unit): Unit

dataBinding

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

Specifies options for the Data Binding Library.

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

debug

Added in 9.0.0-alpha14
fun NamedDomainObjectContainer<TestBuildType>.debug(action: TestBuildType.() -> Unit): Unit

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

For example:

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

defaultConfig

Added in 9.0.0-alpha14
fun defaultConfig(action: TestDefaultConfig.() -> 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 DefaultConfig.

externalNativeBuild

fun externalNativeBuild(action: ExternalNativeBuild.() -> Unit): Unit

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

When using Android Studio 2.2 or higher with Android plugin 2.2.0 or higher, you can compile C and C++ code into a native library that Gradle packages into your APK.

To learn more, read Add C and C++ Code to Your Project.

See also
ExternalNativeBuild

since 2.2.0

installation

Added in 9.0.0-alpha14
fun installation(action: TestInstallation.() -> 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.

jacoco

@Incubating
fun jacoco(action: JacocoOptions.() -> Unit): Unit

Configure the gathering of code-coverage from tests.

This is replaced by testCoverage.

lint

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

Specifies options for the lint tool.

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

lintOptions

@Incubating
fun lintOptions(action: LintOptions.() -> Unit): Unit

Specifies options for the lint tool.

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

packaging

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

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

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

packagingOptions

fun packagingOptions(action: Packaging.() -> Unit): Unit

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

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

privacySandbox

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

productFlavors

Added in 9.0.0-alpha14
fun productFlavors(action: NamedDomainObjectContainer<TestProductFlavor>.() -> Unit): Unit

Encapsulates all product flavors configurations for this project.

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

release

Added in 9.0.0-alpha14
fun NamedDomainObjectContainer<TestBuildType>.release(action: TestBuildType.() -> Unit): Unit

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

For example:

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

signingConfigs

fun signingConfigs(action: NamedDomainObjectContainer<ApkSigningConfig>.() -> Unit): Unit

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

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

sourceSets

fun sourceSets(action: NamedDomainObjectContainer<AndroidSourceSet>.() -> Unit): Unit

Encapsulates source set configurations for all variants.

Note that the Android plugin uses its own implementation of source sets. For more information about the properties you can configure in this block, see AndroidSourceSet.

splits

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

Specifies configurations for building multiple APKs or APK splits.

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

testCoverage

fun testCoverage(action: TestCoverage.() -> Unit): Unit

Configure the gathering of code-coverage from tests.

To override the JaCoCo version that is used for offline instrumentation and coverage report, add the following to build.gradle file:

android {
testCoverage {
jacocoVersion "<jacoco-version>"
}
}

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

testOptions

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

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

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

viewBinding

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

Specifies options for the View Binding Library.

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

Public properties

aaptOptions

val aaptOptionsAaptOptions

Specifies options for the Android Asset Packaging Tool (AAPT).

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

adbOptions

val adbOptionsAdbOptions

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.

androidResources

val androidResourcesTestAndroidResources

Specifies options related to the processing of Android Resources.

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

buildFeatures

val buildFeaturesTestBuildFeatures

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

buildTypes

val buildTypesNamedDomainObjectContainer<TestBuildType>

Encapsulates all build type configurations for this project.

Unlike using TestProductFlavor 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

compileOptions

val compileOptionsCompileOptions

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

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

composeOptions

val composeOptionsComposeOptions

dataBinding

val dataBindingDataBinding

Specifies options for the Data Binding Library.

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

defaultConfig

val defaultConfigTestDefaultConfig

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

externalNativeBuild

val externalNativeBuildExternalNativeBuild

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

When using Android Studio 2.2 or higher with Android plugin 2.2.0 or higher, you can compile C and C++ code into a native library that Gradle packages into your APK.

To learn more, read Add C and C++ Code to Your Project.

See also
ExternalNativeBuild

since 2.2.0

installation

val installationTestInstallation

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.

jacoco

val jacocoJacocoOptions

Configure the gathering of code-coverage from tests.

This is replaced by testCoverage.

lint

val lintLint

Specifies options for the lint tool.

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

lintOptions

val lintOptionsLintOptions

Specifies options for the lint tool.

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

packaging

val packagingPackaging

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

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

packagingOptions

val packagingOptionsPackaging

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

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

privacySandbox

Added in 8.5.0
val privacySandboxPrivacySandbox

Options related to the consumption of privacy sandbox libraries

productFlavors

val productFlavorsNamedDomainObjectContainer<TestProductFlavor>

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 BuildType configurations to create build variants. If the plugin creates certain build variants that you don't want, you can filter variants.

See also
ProductFlavor

signingConfigs

val signingConfigsNamedDomainObjectContainer<ApkSigningConfig>

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

Android requires that all APKs be digitally signed with a certificate before they can be installed onto a device. When deploying a debug version of your project from Android Studio, the Android plugin automatically signs your APK with a generic debug certificate. However, to build an APK for release, you must sign the APK with a release key and keystore. You can do this by either using the Android Studio UI or manually configuring your build.gradle file.

See also
ApkSigningConfig

sourceSets

val sourceSetsNamedDomainObjectContainer<AndroidSourceSet>

Encapsulates source set configurations for all variants.

Note that the Android plugin uses its own implementation of source sets. For more information about the properties you can configure in this block, see AndroidSourceSet.

splits

val splitsSplits

Specifies configurations for building multiple APKs or APK splits.

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

targetProjectPath

Added in 4.2.0
var targetProjectPathString?

The Gradle path of the project that this test project tests.

testCoverage

val testCoverageTestCoverage

Configure the gathering of code-coverage from tests.

To override the JaCoCo version that is used for offline instrumentation and coverage report, add the following to build.gradle file:

android {
testCoverage {
jacocoVersion "<jacoco-version>"
}
}

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

testOptions

val testOptionsTestOptions

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

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

viewBinding

val viewBindingViewBinding

Specifies options for the View Binding Library.

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