KotlinMultiplatformAndroidExtension

@Incubating
public interface KotlinMultiplatformAndroidExtension


Extension properties for Kotlin multiplatform Android libraries.

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

Warning: this is an experimental API and will change in the near future, and you shouldn't publish plugins depending on it.

Summary

Public methods

abstract void

Options for configuring AAR metadata.

abstract void

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

abstract @NonNull AarMetadata

Options for configuring AAR metadata.

abstract @NonNull String

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

abstract Integer

Specifies the API level to compile your project against.

abstract Integer
abstract String
abstract @NonNull DependencyVariantSelection

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

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

Additional per module experimental properties.

abstract @NonNull Lint

Specifies options for the lint tool.

abstract Integer

The maxSdkVersion, or null if not specified.

abstract Integer

The minimum SDK version.

abstract String
abstract String

The namespace of the generated R and BuildConfig classes.

abstract @NonNull KmpOptimization

Specifies options for the R8/D8 optimization tool.

abstract @NonNull Packaging

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

abstract @NonNull TestCoverage

Configure the gathering of code-coverage from tests.

abstract String

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

abstract boolean

Whether core library desugaring is enabled.

abstract void

Specifies options for the lint tool.

abstract void

Specifies options for the R8/D8 optimization tool.

abstract void

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

abstract void

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

abstract void

Specifies the API level to compile your project against.

abstract void
abstract void
abstract void
@Incubating
setCoreLibraryDesugaringEnabled(
    boolean isCoreLibraryDesugaringEnabled
)

Whether core library desugaring is enabled.

abstract void

The maxSdkVersion, or null if not specified.

abstract void

The minimum SDK version.

abstract void
abstract void

The namespace of the generated R and BuildConfig classes.

abstract void

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

abstract void

Includes the specified library to the classpath.

abstract void
@Incubating
useLibrary(@NonNull String name, boolean required)

Includes the specified library to the classpath.

abstract void

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

abstract @NonNull HasConfigurableValue<@NonNull KotlinMultiplatformAndroidTestOnDevice>

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

abstract void

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

abstract @NonNull HasConfigurableValue<@NonNull KotlinMultiplatformAndroidTestOnJvm>

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

Public methods

aarMetadata

@Incubating
abstract void aarMetadata(
    @ExtensionFunctionType @NonNull Function1<@NonNull AarMetadataUnit> action
)

Options for configuring AAR metadata.

dependencyVariantSelection

@Incubating
abstract void dependencyVariantSelection(
    @ExtensionFunctionType @NonNull Function1<@NonNull DependencyVariantSelectionUnit> action
)

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.

getAarMetadata

@Incubating
abstract @NonNull AarMetadata getAarMetadata()

Options for configuring AAR metadata.

getBuildToolsVersion

@Incubating
abstract @NonNull String getBuildToolsVersion()

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.

getCompileSdk

@Incubating
abstract Integer getCompileSdk()

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.

getCompileSdkExtension

@Incubating
abstract Integer getCompileSdkExtension()

getCompileSdkPreview

@Incubating
abstract String getCompileSdkPreview()

getDependencyVariantSelection

@Incubating
abstract @NonNull DependencyVariantSelection getDependencyVariantSelection()

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.

getExperimentalProperties

@Incubating
abstract @NonNull Map<@NonNull String, @NonNull ObjectgetExperimentalProperties()

Additional per module experimental properties.

getLint

@Incubating
abstract @NonNull Lint getLint()

Specifies options for the lint tool.

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

getMaxSdk

@Incubating
abstract Integer getMaxSdk()

The maxSdkVersion, or null if not specified. This is only the value set on this produce flavor.

See uses-sdk element documentation.

getMinSdk

@Incubating
abstract Integer getMinSdk()

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.

getMinSdkPreview

@Incubating
abstract String getMinSdkPreview()

getNamespace

@Incubating
abstract String getNamespace()

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.

getOptimization

@Incubating
abstract @NonNull KmpOptimization getOptimization()

Specifies options for the R8/D8 optimization tool.

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

getPackaging

@Incubating
abstract @NonNull Packaging getPackaging()

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.

getTestCoverage

@Incubating
abstract @NonNull TestCoverage getTestCoverage()

Configure the gathering of code-coverage from tests.

getTestNamespace

@Incubating
abstract String getTestNamespace()

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

isCoreLibraryDesugaringEnabled

@Incubating
abstract boolean isCoreLibraryDesugaringEnabled()

Whether core library desugaring is enabled.

lint

@Incubating
abstract void lint(@ExtensionFunctionType @NonNull Function1<@NonNull LintUnit> action)

Specifies options for the lint tool.

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

optimization

@Incubating
abstract void optimization(
    @ExtensionFunctionType @NonNull Function1<@NonNull KmpOptimizationUnit> action
)

Specifies options for the R8/D8 optimization tool.

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

packaging

@Incubating
abstract void packaging(
    @ExtensionFunctionType @NonNull Function1<@NonNull PackagingUnit> action
)

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.

setBuildToolsVersion

@Incubating
abstract void setBuildToolsVersion(@NonNull String buildToolsVersion)

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.

setCompileSdk

@Incubating
abstract void setCompileSdk(Integer compileSdk)

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.

setCompileSdkExtension

@Incubating
abstract void setCompileSdkExtension(Integer compileSdkExtension)

setCompileSdkPreview

@Incubating
abstract void setCompileSdkPreview(String compileSdkPreview)

setCoreLibraryDesugaringEnabled

@Incubating
abstract void setCoreLibraryDesugaringEnabled(
    boolean isCoreLibraryDesugaringEnabled
)

Whether core library desugaring is enabled.

setMaxSdk

@Incubating
abstract void setMaxSdk(Integer maxSdk)

The maxSdkVersion, or null if not specified. This is only the value set on this produce flavor.

See uses-sdk element documentation.

setMinSdk

@Incubating
abstract void setMinSdk(Integer minSdk)

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.

setMinSdkPreview

@Incubating
abstract void setMinSdkPreview(String minSdkPreview)

setNamespace

@Incubating
abstract void setNamespace(String namespace)

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.

setTestNamespace

@Incubating
abstract void setTestNamespace(String testNamespace)

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

useLibrary

@Incubating
abstract void useLibrary(@NonNull String name)

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
@NonNull String name

the name of the library.

useLibrary

@Incubating
abstract void useLibrary(@NonNull String name, boolean required)

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
@NonNull String name

the name of the library.

boolean required

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

withAndroidTestOnDevice

@Incubating
abstract void withAndroidTestOnDevice(
    @ExtensionFunctionType @NonNull Function1<@NonNull KotlinMultiplatformAndroidTestOnDeviceUnit> action
)

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

  • compilation name is "testOnDevice"

  • 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 KotlinMultiplatformAndroidTestOnDevice options, you can modify it on the kotlin compilation as follows:

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

withAndroidTestOnDeviceBuilder

@Incubating
abstract @NonNull HasConfigurableValue<@NonNull KotlinMultiplatformAndroidTestOnDevicewithAndroidTestOnDeviceBuilder(
    @ExtensionFunctionType @NonNull Function1<@NonNull KotlinMultiplatformAndroidCompilationBuilderUnit> action
)

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

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

kotlin {
androidLibrary {
withAndroidTestOnDeviceBuilder {
compilationName = "instrumentedTest"
defaultSourceSetName = "androidInstrumentedTest"
}.configure {
instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
}
}

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

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

withAndroidTestOnJvm

@Incubating
abstract void withAndroidTestOnJvm(
    @ExtensionFunctionType @NonNull Function1<@NonNull KotlinMultiplatformAndroidTestOnJvmUnit> action
)

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

  • compilation name is "testOnJvm"

  • 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 KotlinMultiplatformAndroidTestOnJvm 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
}
}
}

withAndroidTestOnJvmBuilder

@Incubating
abstract @NonNull HasConfigurableValue<@NonNull KotlinMultiplatformAndroidTestOnJvmwithAndroidTestOnJvmBuilder(
    @ExtensionFunctionType @NonNull Function1<@NonNull KotlinMultiplatformAndroidCompilationBuilderUnit> action
)

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

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

kotlin {
androidLibrary {
withAndroidTestOnJvmBuilder {
compilationName = "unitTest"
defaultSourceSetName = "androidUnitTest"
}.configure {
isIncludeAndroidResources = true
}
}
}

Only a single compilation of this test type can be created. If you want to configure KotlinMultiplatformAndroidTestOnJvm 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
}
}
}