JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.24k stars 1.18k forks source link

@Preview doesn't support Java 19 #2948

Closed ShirasawaSama closed 1 month ago

ShirasawaSama commented 1 year ago

Versions

Error

java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
    at java.base/java.lang.reflect.Method.invoke(Method.java:577)
    at org.jetbrains.compose.desktop.ui.tooling.preview.rpc.PreviewHost.renderFrame(RemotePreviewHost.kt:161)
    at org.jetbrains.compose.desktop.ui.tooling.preview.rpc.PreviewHost.renderFrame(RemotePreviewHost.kt:129)
    at org.jetbrains.compose.desktop.ui.tooling.preview.rpc.PreviewHost.access$renderFrame(RemotePreviewHost.kt:47)
    at org.jetbrains.compose.desktop.ui.tooling.preview.rpc.PreviewHost$senderThread$1.invoke(RemotePreviewHost.kt:63)
    at org.jetbrains.compose.desktop.ui.tooling.preview.rpc.PreviewHost$senderThread$1.invoke(RemotePreviewHost.kt:56)
    at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)
Caused by: java.lang.UnsupportedClassVersionError: {MY_CLASS} has been compiled by a more recent version of the Java Runtime (class file version 63.0), this version of the Java Runtime only recognizes class file versions up to 62.0
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
    at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:524)
    at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:427)
    at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:421)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:420)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:383)
    at java.base/java.lang.Class.forName(Class.java:376)
    at androidx.compose.ui.tooling.ComposableInvoker.invokeComposable(ComposableInvoker.kt:196)
    at androidx.compose.desktop.ui.tooling.preview.runtime.NonInteractivePreviewFacade$Companion$render$1.invoke(NonInteractivePreviewFacade.kt:57)
    at androidx.compose.desktop.ui.tooling.preview.runtime.NonInteractivePreviewFacade$Companion$render$1.invoke(NonInteractivePreviewFacade.kt:53)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
    at androidx.compose.ui.ComposeScene$setContent$5.invoke(ComposeScene.skiko.kt:375)
    at androidx.compose.ui.ComposeScene$setContent$5.invoke(ComposeScene.skiko.kt:374)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
    at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:194)
    at androidx.compose.ui.platform.Wrapper_skikoKt$setContent$2$1.invoke(Wrapper.skiko.kt:47)
    at androidx.compose.ui.platform.Wrapper_skikoKt$setContent$2$1.invoke(Wrapper.skiko.kt:46)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
    at androidx.compose.ui.platform.Wrapper_skikoKt.provide(Wrapper.skiko.kt:63)
    at androidx.compose.ui.platform.Wrapper_skikoKt.access$provide(Wrapper.skiko.kt:1)
    at androidx.compose.ui.platform.Wrapper_skikoKt$setContent$2.invoke(Wrapper.skiko.kt:46)
    at androidx.compose.ui.platform.Wrapper_skikoKt$setContent$2.invoke(Wrapper.skiko.kt:45)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
    at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:37)
    at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3353)
    at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3343)
    at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:341)
    at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(Unknown Source)
    at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3343)
    at androidx.compose.runtime.ComposerImpl.composeContent$runtime(Composer.kt:3278)
    at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:587)
    at androidx.compose.runtime.Recomposer.composeInitial$runtime(Recomposer.kt:966)
    at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:519)
    at androidx.compose.ui.platform.Wrapper_skikoKt.setContent(Wrapper.skiko.kt:45)
    at androidx.compose.ui.ComposeScene.setContent$ui(ComposeScene.skiko.kt:371)
    at androidx.compose.ui.ComposeScene.setContent$ui$default(ComposeScene.skiko.kt:350)
    at androidx.compose.ui.ComposeScene.setContent(ComposeScene.skiko.kt:332)
    at androidx.compose.ui.ImageComposeScene.<init>(ImageComposeScene.skikoMain.kt:120)
    at androidx.compose.ui.ImageComposeScene.<init>(ImageComposeScene.skikoMain.kt:106)
    at androidx.compose.ui.ImageComposeScene_skikoMainKt.renderComposeScene(ImageComposeScene.skikoMain.kt:60)
    at androidx.compose.desktop.ui.tooling.preview.runtime.NonInteractivePreviewFacade$Companion.render(NonInteractivePreviewFacade.kt:53)
    at androidx.compose.desktop.ui.tooling.preview.runtime.NonInteractivePreviewFacade.render(NonInteractivePreviewFacade.kt)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
    ... 7 more
AlexeyTsvetkov commented 1 year ago

@ShirasawaSama I was not able to reproduce the issue. How do you configure target bytecode level/JDK in your Gradle scripts?

kvithayathil commented 11 months ago

I got the same error - using the generated project from the KMP Wizard. When I updated all the jvm targets and toolchains to anything above Java Version 17, I'd encounter the similar errors with @Preview on desktop. Android previews do work however.

Setting the Java Version to 17 does allow desktop previews to work.

okushnikov commented 2 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.