英文:
Getting error: Execution failed for task ':app:kaptGenerateStubsDebugKotlin'. after upgrading to Android Studio Flamingo | 2022.2.1
问题
After updating Android Studio version to 2022.2.1,I started to get this error when trying to compile the project:
> Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.<br>
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'kaptGenerateStubsDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.<br>
> Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain
My gradle:
compileSdk 33
defaultConfig {
minSdk 23
targetSdk 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.incremental": "true"]
}
}
consumerProguardFiles 'proguard-rules.pro'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
How to fix this error?
Android Studio Flamingo | 2022.2.1<br>
Build #AI-222.4459.24.2221.9862592, built on March 31, 2023<br>
Runtime version: 17.0.6+0-17.0.6b802.4-9586694 aarch64<br>
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.<br>
macOS 13.3.1
英文:
After updating Android Studio version to 2022.2.1 I started to get this error when trying to compile the project:
> Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.<br>
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'kaptGenerateStubsDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.<br>
> Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain
My gradle:
compileSdk 33
defaultConfig {
minSdk 23
targetSdk 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.incremental": "true"]
}
}
consumerProguardFiles 'proguard-rules.pro'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
How to fix this error?
Android Studio Flamingo | 2022.2.1<br>
Build #AI-222.4459.24.2221.9862592, built on March 31, 2023<br>
Runtime version: 17.0.6+0-17.0.6b802.4-9586694 aarch64<br>
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.<br>
macOS 13.3.1
答案1
得分: 2
If you updated Gradle
to version 8.0.0
along with the Flamingo 2022.2.1 update, then you need to update the JDK
to version 17
.
You can see the compatibility table here.
The following code in app level build.gradle should solve your problem:
android {
...
compileOptions {
sourceCompatibilityJavaVersion.VERSION_17
targetCompatibilityJavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
...
}
英文:
If you updated Gradle
to version 8.0.0
along with the Flamingo 2022.2.1 update, then you need to update the JDK
to version 17
You can see the compatibility table here.
The following code in app level build.gradle should solve your problem:
android {
...
compileOptions {
sourceCompatibilityJavaVersion.VERSION_17
targetCompatibilityJavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
...
}
答案2
得分: 0
这在Android Studio Giraffe上运行良好。
根据此工具链文档。
将此内容添加到应用程序gradle文件中可解决我的问题。
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
//important
kotlin {
jvmToolchain(18)
}
英文:
This worked well for Android Studio Giraffe
As per This Toolchain Documentation
Adding this in the app gradle file fixed the issue for me.
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
//important
kotlin {
jvmToolchain(18)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论