新安装的 Android Studio Narwhal | 2025.1.1 Patch 1 又是一堆问题。
编译时,报错:
Unknown Kotlin JVM target: 21
Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.
> Error while evaluating property 'compilerOptions.jvmTarget' of task ':app:kaptGenerateStubsDebugKotlin'.
> Failed to calculate the value of property 'jvmTarget'.
> Unknown Kotlin JVM target: 21
这个项目使用是是 Kotlin 1.8,而 1.8 支持的最高 jvmTarget 版本是 17.
Current Kotlin Support: As of Kotlin 1.8 and 1.9, the maximum officially supported jvmTarget is 17.
奇怪
即便 build.gradle 中指定了 JavaVersion.VERSION_17 和 jvmTarget = '17',都没有用,依旧报错:
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
修改 Kotlin JVM target
Settings -> Build, Execution, Deployment -> Build Tools -> Gradle.
"Gradle JDK" 选择 "corretto-17 Amazon Corretto 17.0.13"
实际,我选择的是微软那个 JDK 17。然后就搞定了 👌
(而选择 JetBrains 那个 17 还是会报上面那个错。)
参考
https://stackoverflow.com/questions/78970867/error-appkaptgeneratestubsdebugkotlin-and-unknown-kotlin-jvm-target-21-after
关于作者 🌱
我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式