KotlinMultiplatformAndroidLibraryExtension

Added in 8.9.0-alpha03

interface KotlinMultiplatformAndroidLibraryExtension

Known direct subclasses
KotlinMultiplatformAndroidLibraryTarget
KotlinMultiplatformAndroidTarget

This interface is deprecated. Use KotlinMultiplatformAndroidLibraryTarget.


Extension properties for Kotlin multiplatform Android libraries.

Only the Kotlin Multiplatform Android Plugin should create instances of this interface.

Summary

Public functions

Unit
aarMetadata(action: AarMetadata.() -> Unit)

Options for configuring AAR metadata.

Unit

Specifies options for doing variant selection for external Android dependencies based on build types and product flavours

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

Specifies options for the lint tool.

Unit

Specifies options for the R8/D8 optimization tool.

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

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

Unit

Includes the specified library to the classpath.

Unit
useLibrary(name: String, required: Boolean)

Includes the specified library to the classpath.

Unit

This function is deprecated. Use withDeviceTest.

HasConfigurableValue<KotlinMultiplatformAndroidDeviceTest>

This function is deprecated. Use withDeviceTestBuilder.

Unit

This function is deprecated. Use withHostTest.

HasConfigurableValue<KotlinMultiplatformAndroidHostTest>

This function is deprecated. Use withHostTestBuilder.

Unit

Creates and configures a compilation for tests that run on the device (previously referred to as instrumented tests).

HasConfigurableValue<KotlinMultiplatformAndroidDeviceTest>

Creates and configures a compilation for tests that run on the device (previously referred to as instrumented tests).

Unit

Creates and configures a compilation for tests that run on the JVM (previously referred to as unit tests).

HasConfigurableValue<KotlinMultiplatformAndroidHostTest>

Creates and configures a compilation for tests that run on the JVM (previously referred to as unit tests).

Public properties

AarMetadata

Options for configuring AAR metadata.

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?
String?
DependencyVariantSelection

Specifies options for doing variant selection for external Android dependencies based on build types and product flavours

Boolean

Whether core library desugaring is enabled.

MutableMap<StringAny>

Additional per module experimental properties.

Lint

Specifies options for the lint tool.

Int?

The minimum SDK version.

String?
String?

The namespace of the generated R and BuildConfig classes.

KmpOptimization

Specifies options for the R8/D8 optimization tool.

Packaging

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

TestCoverage

Configure the gathering of code-coverage from tests.

String?

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

Public functions

aarMetadata

Added in 8.9.0-alpha03
fun aarMetadata(action: AarMetadata.() -> Unit): Unit

Options for configuring AAR metadata.

dependencyVariantSelection

Added in 8.9.0-alpha03
@Incubating
fun dependencyVariantSelection(action: DependencyVariantSelection.() -> Unit): Unit

Specifies options for doing variant selection for external Android dependencies based on build types and product flavours

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

lint

Added in 8.9.0-alpha03
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.

optimization

Added in 8.9.0-alpha03
@Incubating
fun optimization(action: KmpOptimization.() -> Unit): Unit

Specifies options for the R8/D8 optimization tool.

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

packaging

Added in 8.9.0-alpha03
fun packaging(action: Packaging.() -> Unit): Unit

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

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

useLibrary

Added in 8.9.0-alpha03
fun useLibrary(name: String): Unit

Includes the specified library to the classpath.

You typically use this property to support optional platform libraries that ship with the Android SDK. The following sample adds the Apache HTTP API library to the project classpath:

android {
// Adds a platform library that ships with the Android SDK.
useLibrary 'org.apache.http.legacy'
}

To include libraries that do not ship with the SDK, such as local library modules or binaries from remote repositories, add the libraries as dependencies in the dependencies block. Note that Android plugin 3.0.0 and later introduce new dependency configurations. To learn more about Gradle dependencies, read Dependency Management Basics.

Parameters
name: String

the name of the library.

useLibrary

Added in 8.9.0-alpha03
fun useLibrary(name: String, required: Boolean): Unit

Includes the specified library to the classpath.

You typically use this property to support optional platform libraries that ship with the Android SDK. The following sample adds the Apache HTTP API library to the project classpath:

android {
// Adds a platform library that ships with the Android SDK.
useLibrary 'org.apache.http.legacy'
}

To include libraries that do not ship with the SDK, such as local library modules or binaries from remote repositories, "https://developer.android.com/studio/build/dependencies.html in the dependencies block. Note that Android plugin 3.0.0 and later introduce new dependency configurations. To learn more about Gradle dependencies, read Dependency Management Basics

Parameters
name: String

the name of the library.

required: Boolean

if using the library requires a manifest entry, the entry will indicate that the library is not required.

withAndroidTestOnDevice

Added in 8.9.0-alpha03
Deprecated in 8.9.0-alpha03
fun withAndroidTestOnDevice(action: KotlinMultiplatformAndroidDeviceTest.() -> Unit): Unit

withAndroidTestOnDeviceBuilder

Added in 8.9.0-alpha03
Deprecated in 8.9.0-alpha03
@Incubating
fun withAndroidTestOnDeviceBuilder(action: KotlinMultiplatformAndroidCompilationBuilder.() -> Unit): HasConfigurableValue<KotlinMultiplatformAndroidDeviceTest>

withAndroidTestOnJvm

Added in 8.9.0-alpha03
Deprecated in 8.9.0-alpha03
fun withAndroidTestOnJvm(action: KotlinMultiplatformAndroidHostTest.() -> Unit): Unit

withAndroidTestOnJvmBuilder

Added in 8.9.0-alpha03
Deprecated in 8.9.0-alpha03
@Incubating
fun withAndroidTestOnJvmBuilder(action: KotlinMultiplatformAndroidCompilationBuilder.() -> Unit): HasConfigurableValue<KotlinMultiplatformAndroidHostTest>

withDeviceTest

Added in 8.9.0-alpha03
fun withDeviceTest(action: KotlinMultiplatformAndroidDeviceTest.() -> Unit): Unit

Creates and configures a compilation for tests that run on the device (previously referred to as instrumented tests). Invoking this method will create a KotlinMultiplatformAndroidDeviceTestCompilation object with the following defaults:

  • compilation name is "deviceTest"

  • default sourceSet name is "androidTestOnDevice" (sources would be located at $project/src/androidTestOnDevice)

  • sourceSet tree is null, which means that the commonTest sourceSet will not be included in the compilation.

Only a single compilation of this test type can be created. If you want to configure KotlinMultiplatformAndroidDeviceTest options, you can modify it on the kotlin compilation as follows:

kotlin {
androidLibrary {
compilations.withType(com.android.build.api.dsl.KotlinMultiplatformAndroidDeviceTest::class.java) {
// configure options
}
}
}

withDeviceTestBuilder

Added in 8.9.0-alpha03
@Incubating
fun withDeviceTestBuilder(action: KotlinMultiplatformAndroidCompilationBuilder.() -> Unit): HasConfigurableValue<KotlinMultiplatformAndroidDeviceTest>

Creates and configures a compilation for tests that run on the device (previously referred to as instrumented tests). Invoking this method will create a KotlinMultiplatformAndroidDeviceTestCompilation object using the values set in the KotlinMultiplatformAndroidCompilationBuilder.

The returned object can be used to configure KotlinMultiplatformAndroidDeviceTest as follows:

kotlin {
androidLibrary {
withDeviceTestBuilder {
}.configure {
instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
}
}

Only a single compilation of this test type can be created. If you want to configure KotlinMultiplatformAndroidDeviceTest options, you can modify it on the kotlin compilation as follows:

kotlin {
androidLibrary {
compilations.withType(com.android.build.api.dsl.KotlinMultiplatformAndroidDeviceTest::class.java) {
// configure options
}
}
}

withHostTest

Added in 8.9.0-alpha03
fun withHostTest(action: KotlinMultiplatformAndroidHostTest.() -> Unit): Unit

Creates and configures a compilation for tests that run on the JVM (previously referred to as unit tests). Invoking this method will create a KotlinMultiplatformAndroidHostTestCompilation object with the following defaults (You can change these defaults by using withHostTestBuilder instead):

  • compilation name is "hostTest"

  • default sourceSet name is "androidTestOnJvm" (sources would be located at $project/src/androidTestOnJvm)

  • sourceSet tree is test, which means that the commonTest sourceSet would be included in the compilation.

Only a single compilation of this test type can be created. If you want to configure KotlinMultiplatformAndroidHostTest options, you can modify it on the kotlin compilation as follows:

kotlin {
androidLibrary {
compilations.withType(com.android.build.api.dsl.KotlinMultiplatformAndroidTestOnJvm::class.java) {
// configure options
}
}
}

withHostTestBuilder

Added in 8.9.0-alpha03
@Incubating
fun withHostTestBuilder(action: KotlinMultiplatformAndroidCompilationBuilder.() -> Unit): HasConfigurableValue<KotlinMultiplatformAndroidHostTest>

Creates and configures a compilation for tests that run on the JVM (previously referred to as unit tests). Invoking this method will create a KotlinMultiplatformAndroidHostTestCompilation object using the values set in the KotlinMultiplatformAndroidCompilationBuilder.

The returned object can be used to configure KotlinMultiplatformAndroidHostTest as follows:

kotlin {
androidLibrary {
withHostTestBuilder {
}.configure {
isIncludeAndroidResources = true
}
}
}

Only a single compilation of this test type can be created. If you want to configure KotlinMultiplatformAndroidHostTest options, you can modify it on the kotlin compilation as follows:

kotlin {
androidLibrary {
compilations.withType(com.android.build.api.dsl.KotlinMultiplatformAndroidTestOnJvm::class.java) {
// configure options
}
}
}

Public properties

aarMetadata

Added in 8.9.0-alpha03
val aarMetadataAarMetadata

Options for configuring AAR metadata.

buildToolsVersion

Added in 8.9.0-alpha03
var buildToolsVersionString

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

By default, the plugin uses the minimum version of the build tools required by the version of the plugin you're using. To specify a different version of the build tools for the plugin to use, specify the version as follows:

android {
// Specifying this property is optional.
buildToolsVersion "26.0.0"
}

For a list of build tools releases, read the release notes.

Note that the value assigned to this property is parsed and stored in a normalized form, so reading it back may give a slightly different result.

compileSdk

Added in 8.9.0-alpha03
var compileSdkInt?

Specifies the API level to compile your project against. The Android plugin requires you to configure this property.

This means your code can use only the Android APIs included in that API level and lower. You can configure the compile sdk version by adding the following to the android block: compileSdk = 26.

You should generally use the most up-to-date API level available. If you are planning to also support older API levels, it's good practice to use the Lint tool to check if you are using APIs that are not available in earlier API levels.

The value you assign to this property is parsed and stored in a normalized form, so reading it back may return a slightly different value.

compileSdkExtension

Added in 8.9.0-alpha03
var compileSdkExtensionInt?

compileSdkPreview

Added in 8.9.0-alpha03
var compileSdkPreviewString?

dependencyVariantSelection

Added in 8.9.0-alpha03
val dependencyVariantSelectionDependencyVariantSelection

Specifies options for doing variant selection for external Android dependencies based on build types and product flavours

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

enableCoreLibraryDesugaring

Added in 8.9.0-alpha03
var enableCoreLibraryDesugaringBoolean

Whether core library desugaring is enabled.

experimentalProperties

Added in 8.9.0-alpha03
val experimentalPropertiesMutableMap<StringAny>

Additional per module experimental properties.

lint

Added in 8.9.0-alpha03
val lintLint

Specifies options for the lint tool.

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

minSdk

Added in 8.9.0-alpha03
var minSdkInt?

The minimum SDK version. Setting this it will override previous calls of minSdk and minSdkPreview setters. Only one of minSdk and minSdkPreview should be set.

See uses-sdk element documentation.

minSdkPreview

Added in 8.9.0-alpha03
var minSdkPreviewString?

namespace

Added in 8.9.0-alpha03
var namespaceString?

The namespace of the generated R and BuildConfig classes. Also, the namespace used to resolve any relative class names that are declared in the AndroidManifest.xml.

optimization

Added in 8.9.0-alpha03
val optimizationKmpOptimization

Specifies options for the R8/D8 optimization tool.

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

packaging

Added in 8.9.0-alpha03
val packagingPackaging

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

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

testCoverage

Added in 8.9.0-alpha03
val testCoverageTestCoverage

Configure the gathering of code-coverage from tests.

testNamespace

Added in 8.9.0-alpha03
var testNamespaceString?

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