Hi, I have a problem with Android Studio (version ...
# android
g
Hi, I have a problem with Android Studio (version arwhal 4 Feature Drop | 2025.1.4) and kotlin versions: The IDE does not recognize the correct kotlin language version I am using (2.2.20). The features I use (e.g. Clock Interface) work fine when building, but the IDE shows an error saying "This declaration is only available in Kotlin 2.1 ...". Now when I try to change the language version in the settings, it does not work, it still shows the same error and when restarting IDE it jumps back to 2.0, even though in my gradle i definitely have 2.2.20 configured. This is my gradle:
Copy code
agp = "8.13.0"
kotlin = "2.2.20"

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
Copy code
plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.androidApplication)
...
}

kotlin {
    sourceSets.all {
        languageSettings {
            optIn("kotlin.uuid.ExperimentalUuidApi")
        }
    }

    androidTarget {
        compilerOptions {
            jvmTarget.set(JvmTarget.JVM_21)
        }
    }
...
}
And in the settings it looks like this:
r
You must use `kotlin { compilerOptions { language..., optin`s...
}}
Source sets configuration blocks are only for extending the global (or common) configuration, for example, adding more opt-ins on iOS. Maybe this help u, if it isn't maybe is the version of the IDE / plugins
g
thank you , that was not it but something similar. i had to set the versions manually in gradle like this:
Copy code
kotlin {
    compilerOptions {
        optIn.add("kotlin.uuid.ExperimentalUuidApi")
        languageVersion.set(KotlinVersion.KOTLIN_2_2)
        apiVersion.set(KotlinVersion.KOTLIN_2_2)
    }
seems a bit odd to me that this is necessary though...
c
Most probably you have a plugin applied that uses an old language version. You should see that in the logs when running a Gradle task. I.e. kapt is in maintenance mode and uses 1.9 as language version.
g
ah that is the reason, thank you