19

I'm encountering an issue while trying to build my Android project using AndroidX Compose. I'm getting the following error message:

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

It seems that my current Java Runtime Environment (JRE) is outdated and does not support the class file version used by the AndroidX Compose library.

Environment details:

  • Java version: JDK 17
  • AndroidX Compose version: 1.4.5
  • Build system: Gradle 8.1
  • Kotlin: 1.8.20
./gradlew  -version | grep JVM

output: JVM: 17.0.6 (JetBrains s.r.o. 17.0.6+10-b802.4)

Based on note from here JDK 17 must work.

I would like to know the best way to resolve this issue. Should I update my JDK and JRE to a more recent version, or is there a way to use a compatible version of the AndroidX Compose library with my current JDK?

Any help or suggestions would be appreciated. Thanks!

4
  • What are you setting of the following compileOptions? - sourceCompatibility - targetCompatibility Commented Apr 13, 2023 at 7:18
  • I'm experiencing this issue as well with the latest upgrade of the compose compiler, so it might be an issue with the latest version 1.4.5. Let me suggest you post a new issue here issuetracker.google.com/issues/new Commented Apr 13, 2023 at 8:35
  • 1
    Your IDE is using jdk version 11 (class file version 55). That's why you are getting this error. Try to restart IDE. Commented Apr 13, 2023 at 8:58
  • I had the same setup as yours the only thing that fixed it was updating my Android Studio to Flamingo. Commented Apr 14, 2023 at 11:17

7 Answers 7

7

Check the NOTE here: Compose Compiler | Jetpack | Android Developers

screenshot of above web page

So, if not using Java 17+ stick to Compose Compiler 1.4.4 & wait till 1.4.6 release for older Java version support.

Sign up to request clarification or add additional context in comments.

Comments

5

Just use previous version of Compose (1.4.4) and Kotlin (1.8.10)

Comments

1

Use

kotlin {
   jvmToolchain(17)
}

and

compileOptions {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

Checkout release notes: https://developer.android.com/jetpack/androidx/releases/compose-compiler#1.4.5

Comments

1

There are problems in: compose-compiler#1.4.5

NOTE This build of Compose Compiler requires your build environment to use Java 17+. Based on user feedback, we will drop this requirement back to Java 11 and follow-up with another release (1.4.6) to better support users who are using older Java versions.

You can temporarily fix editing these variables in the file .\gradle\libs.versions.toml until androidxComposeCompiler#1.4.6 will be published

Edit these variables in the file .\gradle\libs.versions.toml

androidxComposeCompiler = "1.4.4"
kotlin = "1.8.10"
ksp = "1.8.10-1.0.9"

Comments

1

The only thing which worked for me was updating to Android Studio Flamingo and deleting all old Java installations. I removed everything which was listed in /usr/libexec/java_home -V and mdfind -name 'java' | grep '/bin/java$' that was not Java 17 and set the JDK inside Android Studio to the embedded one. After restarting AS and a project clean, the build succeeded.

Comments

1

I had this same problem and I was able to fix it by updating android studio to flamingo 2022.2.1, then it asked me to upgrade AGP to 8.0. After it completed, I set kotlin version to 1.8.20, kotlinCompilerExtensionVersion to 1.4.5 and both sourceCompatibility and targetCompatibility in compileOptions to JavaVersion.VERSION_17.

2 Comments

I guess you mean compileOptions instead of composeOptions?
@LN-12 you're right. I corrected. Thanks!
0

Meanwhile you can also switch to ComposeCompiler 1.4.6 which depends again on Java 11 and works with Kotlin 1.8.20

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.