Reputation: 6703
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'.
'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.
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
Build #AI-222.4459.24.2221.9862592, built on March 31, 2023
Runtime version: 17.0.6+0-17.0.6b802.4-9586694 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 13.3.1
Upvotes: 1
Views: 1659
Reputation: 2779
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)
}
Upvotes: 0
Reputation: 1917
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'
}
...
}
Upvotes: 2