# CompileSdkSpec

[View Source](https://cs.android.com/search?q=file:com/android/build/api/dsl/CompileSdkSpec.kt+class:com.android.build.api.dsl.CompileSdkSpec) Added in 8.13.0


```
interface CompileSdkSpec
```

<br />

*** ** * ** ***

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](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) available.

If you are planning to also support older API levels, it's good practice to [use the Lint tool](https://developer.android.com/studio/write/lint.html) to check if you are using APIs that are not available in earlier API levels.

This can be set on all Gradle projects with `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/SettingsExtension#compileSdk(kotlin.Function1)`

## Summary

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` | `@org.gradle.declarative.dsl.model.annotations.HiddenInDefinition https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#addon(kotlin.String,kotlin.String,kotlin.Int)(vendor: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, name: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html, version: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Specify an SDK add-on to compile your project against. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` | `@org.gradle.declarative.dsl.model.annotations.HiddenInDefinition https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#beta(kotlin.Int,kotlin.Function1)(version: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, action: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkBetaSpec.() -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` To set compile SDK version with a beta version, use this function to compute the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` and assign it to `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#version()` property. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` | `@org.gradle.declarative.dsl.model.annotations.HiddenInDefinition https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#canary(kotlin.String)(date: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` To set compile SDK version with a canary version, use this function to compute the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` and assign it to `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#version()` property. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` | `@org.gradle.declarative.dsl.model.annotations.HiddenInDefinition https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#preview(kotlin.String)(codeName: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` To set compile SDK version with a preview API level, use this function to compute the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` and assign it to `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#version()` property. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` | `@org.gradle.declarative.dsl.model.annotations.HiddenInDefinition https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#release(kotlin.Int)(version: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` To set compile SDK version with a released API level, use this function to compute the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` and assign it to `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#version()` property. |
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` | `@org.gradle.declarative.dsl.model.annotations.HiddenInDefinition https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#release(kotlin.Int,kotlin.Function1)(version: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, action: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkReleaseSpec.() -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)` To set compile SDK version with a released API level, use this function to compute the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` and assign it to `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#version()` property. |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion?` | `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#version()` The compile SDK version set for this project. |

## Public functions

### addon

Added in 8.13.0

```
@org.gradle.declarative.dsl.model.annotations.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 `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/SettingsExtension#compileSdkAddon(kotlin.String,kotlin.String,kotlin.Int)`

| Parameters |
|---|---|
| `vendor: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | the vendor name of the add-on. |
| `name: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | the name of the add-on |
| `version: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | the integer API level of the add-on |

### beta

Added in 9.6.0-alpha03

```
@org.gradle.declarative.dsl.model.annotations.HiddenInDefinition
fun beta(version: Int, action: CompileSdkBetaSpec.() -> Unit): CompileSdkVersion
```

To set compile SDK version with a beta version, use this function to compute the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` and assign it to `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#version()` property.

| Parameters |
|---|---|
| `version: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | the major API level. |
| `action: https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkBetaSpec.() -> https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | a lambda for further configuration of minor API level and beta version. |

### canary

Added in 9.6.0-alpha03

```
@org.gradle.declarative.dsl.model.annotations.HiddenInDefinition
fun canary(date: String): CompileSdkVersion
```

To set compile SDK version with a canary version, use this function to compute the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` and assign it to `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#version()` property.

| Parameters |
|---|---|
| `date: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | a string representing the date (e.g., "20250617"). |

### preview

Added in 8.13.0

```
@org.gradle.declarative.dsl.model.annotations.HiddenInDefinition
fun preview(codeName: String): CompileSdkVersion
```

To set compile SDK version with a preview API level, use this function to compute the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` and assign it to `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#version()` property.

### release

Added in 8.13.0

```
@org.gradle.declarative.dsl.model.annotations.HiddenInDefinition
fun release(version: Int): CompileSdkVersion
```

To set compile SDK version with a released API level, use this function to compute the `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` and assign it to `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#version()` property.

### release

Added in 8.13.0

```
@org.gradle.declarative.dsl.model.annotations.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 `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkVersion` and assign it to `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkSpec#version()` property. When using a released API level, you can also set minor API level and SDK extension level via `https://developer.android.com/reference/tools/gradle-api/9.6/com/android/build/api/dsl/CompileSdkReleaseSpec` block.

## Public properties

### version

Added in 8.13.0

```
var version: CompileSdkVersion?
```

The compile SDK version set for this project.