https://kotlinlang.org logo
Title
c

Charlie Tapping

04/14/2023, 11:44 AM
I’m getting this error
androidx/compose/compiler/plugins/kotlin/ComposeComponentRegistrar has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0.
55 Being Java 11 and 61 being 17 (I guess the latest compose was compiled on a machine with 17) Now Gradle is running with Java 18 I’ve set the toolchain to use 18 with:
kotlin {
    jvmToolchain {
        languageVersion.set(JavaLanguageVersion.of(libs.versions.java.compile.version.get().toInt())) //compile = 18
        vendor.set(JvmVendorSpec.ADOPTIUM)
    }
}
I’ve set the kotlin compile tasks to output Java 11 bytecode:
tasks.withType<KotlinCompile>().configureEach {
    compilerOptions {
        jvmTarget.set(JvmTarget.fromTarget(libs.versions.java.bytecode.version.get())) bytecode = 11
    }
}
On AGP I configured the same
compileOptions {
    sourceCompatibility = JavaVersion.toVersion(libs.versions.java.bytecode.version.get().toInt())
    targetCompatibility = JavaVersion.toVersion(libs.versions.java.bytecode.version.get().toInt())
}

kotlinOptions {
    jvmTarget = libs.versions.java.bytecode.version.get()
}
I really don’t understand how I could be running Java 11 runtime, its like kapt is reading the jvmTarget as the runtime rather than the bytecode target?
Your Gradle is evidently not running under Java 18. Check the output of
$JAVA_HOME/bin/java --version
and
java --version
Setting the toolchain will change the version of javac used for compilation, but gradle still runs with system java.
c

Charlie Tapping

04/14/2023, 1:27 PM
Forgot to say I’m doing all of this in Android Studio, so checking JAVA_HOME won’t work because AS has its own overrides
for example if I run
./gradlew --version ------------------------------------------------------------ Gradle 8.1 ------------------------------------------------------------ Build time: 2023-04-12 12:07:45 UTC Revision: 40ba32cde9d6daf2b92c39376d2758909dd6b813 Kotlin: 1.8.10 Groovy: 3.0.15 Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021 JVM: 19.0.2 (Homebrew 19.0.2) OS: Mac OS X 13.2.1 aarch64
My system is actually set to 19
As itself is set to run 18
image.png
I’ve now aligned AS to 19 and the same result
Reading the docs KGP I get the impression the use case of compiling with a modern compiler 19 and targeting older bytecode isn’t being considered
Further to this I noticed the error was being thrown from the incremental compiler, to be safe I nuked my gradle cache and reran and that fixed everything
h

Hackintoshfive

04/14/2023, 6:44 PM
Classic. I had an issue today (I forget what it was) but running
gradle --stop
fixed it