CompileSdkSpec

Added in 8.13.0

interface CompileSdkSpec


Specifies the API level to compile your project against, which is required by the Android plugin.

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 block:

android {
compileSdk {
version = release(33) {
// this block and its properties are optional
minorApiLevel = 1
sdkExtension = 18
}
}
}

or to use a preview version:

android {
compileSdk {
version = preview("Tiramisu")
}
}

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.

This can be set on all Gradle projects with com.android.build.api.dsl.SettingsExtension.compileSdk

Summary

Public functions

CompileSdkVersion
@HiddenInDefinition
addon(vendor: String, name: String, version: Int)

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

CompileSdkVersion
@HiddenInDefinition
beta(version: Int, action: CompileSdkBetaSpec.() -> Unit)

To set compile SDK version with a beta version, use this function to compute the CompileSdkVersion and assign it to CompileSdkSpec.version property.

CompileSdkVersion

To set compile SDK version with a canary version, use this function to compute the CompileSdkVersion and assign it to CompileSdkSpec.version property.

CompileSdkVersion

To set compile SDK version with a preview API level, use this function to compute the CompileSdkVersion and assign it to CompileSdkSpec.version property.

CompileSdkVersion

To set compile SDK version with a released API level, use this function to compute the CompileSdkVersion and assign it to CompileSdkSpec.version property.

CompileSdkVersion

To set compile SDK version with a released API level, use this function to compute the CompileSdkVersion and assign it to CompileSdkSpec.version property.

Public properties

CompileSdkVersion?

The compile SDK version set for this project.

Public functions

addon

Added in 8.13.0
@HiddenInDefinition
fun addon(vendor: String, name: String, version: Int): CompileSdkVersion

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

This can be set on all Gradle projects with com.android.build.api.dsl.SettingsExtension.compileSdkAddon

Parameters
vendor: String

the vendor name of the add-on.

name: String

the name of the add-on

version: Int

the integer API level of the add-on

beta

Added in 9.2.0-alpha06
@HiddenInDefinition
fun beta(version: Int, action: CompileSdkBetaSpec.() -> Unit): CompileSdkVersion

To set compile SDK version with a beta version, use this function to compute the CompileSdkVersion and assign it to CompileSdkSpec.version property.

Parameters
version: Int

the major API level.

action: CompileSdkBetaSpec.() -> Unit

a lambda for further configuration of minor API level and beta version.

canary

Added in 9.2.0-alpha06
@HiddenInDefinition
fun canary(date: String): CompileSdkVersion

To set compile SDK version with a canary version, use this function to compute the CompileSdkVersion and assign it to CompileSdkSpec.version property.

Parameters
date: String

a string representing the date (e.g., "20250617").

preview

Added in 8.13.0
@HiddenInDefinition
fun preview(codeName: String): CompileSdkVersion

To set compile SDK version with a preview API level, use this function to compute the CompileSdkVersion and assign it to CompileSdkSpec.version property.

release

Added in 8.13.0
@HiddenInDefinition
fun release(version: Int): CompileSdkVersion

To set compile SDK version with a released API level, use this function to compute the CompileSdkVersion and assign it to CompileSdkSpec.version property.

release

Added in 8.13.0
@HiddenInDefinition
fun release(version: Int, action: CompileSdkReleaseSpec.() -> Unit): CompileSdkVersion

To set compile SDK version with a released API level, use this function to compute the CompileSdkVersion and assign it to CompileSdkSpec.version property. When using a released API level, you can also set minor API level and SDK extension level via CompileSdkReleaseSpec block.

Public properties

version

Added in 8.13.0
var versionCompileSdkVersion?

The compile SDK version set for this project.