Search code examples
androidandroid-studiobuild.gradleandroid-jetpack-composegradle-kotlin-dsl

What is difference between compileSdk and compileSdkVersion in android studio gradle script when using jetpack compose


When I created new android project with jetpack compose toolkit with or without kotlin dsl I found that in module level build.gradle file the property compileSdkVersion has been replaced by compileSdk. I also found that android sdk version "android-S" couldn't be added to compileSdk for that compileSdkVersion = "android-S" needed to be added seperately. My question is what exactly is difference between compileSdk and compileSdkVersion.

build.gradle.kts(Module:Compose.app)

android {
    compileSdk = 30
    buildToolsVersion = "30.0.3"
    compileSdkVersion = "android-S"
}

Solution

  • With the new Android Gradle Plugin 7.0.0 (currently 7.0.0-alpha14) you can use:

    These attributes work with an Int and you can use them with something like:

    //minSdkVersion 21
    //targetSdkVersion 30
    minSdk 21
    targetSdk 30
    

    If you want to use a preview version you have to use:

    These attributes work with a String and setting these values will override previous values of minSdk/targetSdk/compileSdk.

    About the String format of the preview versions currently (7.0.0-alpha14) it is not clear. Maybe it will change with 7.0.0-beta01 (you can check this commit) and it should be:

    compileSdkPreview = "S"