I have tried all of the listed solutions I can find on the Internet and am stumped.
I’m updating to Java 17 from 1.8, and I am getting the error:
Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'kaptGenerateStubsDebugKotlin' (17).
- I have changed all of the recommended options
- I have Invalidated Caches and Restarted Multiple Times
- I have Cleaned the project many many times
- Each of the above was done after each one of the following changes
Module build.gradle:
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
tasks.withType(KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = '17'
}
}
App level build.gradle
tasks.withType(KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs += [
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=1.9.0",
"-Xjvm-default=all",
]
}
}
...
kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas")
arg("kapt.jvmTarget", "17")
}
}
Project level build.gradle:
dependencies {
classpath 'com.android.tools:r8:8.3.37'
classpath 'com.android.tools.build:gradle:8.2.2'
...
build.gradle.kts:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.9.24"
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "17"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "17"
}
gradle.properties:
// Commented out top line to switch to the bottom to prevent daemon errors
#org.gradle.jvmargs=-Xmx14g -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseConcMarkSweepGC
org.gradle.jvmargs=-Xmx1024m
// Added this line
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
gradle-wrapper.properties:
distributionUrl=https://services.gradle.org/distributions/gradle-8.4-rc-1-bin.zip
Added line to ~/.zshrc:
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
Gradle Settings:
Project Structure:
- I have changed all of the recommended options
- I have Invalidated Caches and Restarted Multiple Times
- I have Cleaned the project many many times
- I have removed all of the Java 8 JDKs
- Each of the above was done after each one of the following changes
The project will not build because of the error:
Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'kaptGenerateStubsDebugKotlin' (17).