[Android] 更新Android Studio后报错 Unknown Kotlin JVM target: 21

2023.3.1升级至2024.3.1后,报错信息如下:

Execution failed for task ':app:compileDebugKotlin'
> Error while evaluating property 'compilerOptions.jvmTarget' of task ':app:compileDebugKotlin'
> Failed to calculate the value of property 'jvmTarget'
> Unknown Kotlin JVM target: 21

解决方法:

1. 升级 gradle 版本(按自己实际)gradle/wrapper/gradle-wrapper.properties

    distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip

    2. 升级 gradle 插件版本 及 kotlin 版本(按自己实际)

    classpath 'com.android.tools.build:gradle:8.2.2'
    classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0'

    3. sync & rebuild

    发表评论


    *