I have the latest 2021.1.1 Patch 2 and latest Compose libraries, have been trying many things but keep getting an exception in the Compose Preview Window.
I'm getting The red "The project needs to be compiled successfully " message and when clicking on Info I get the below exception.
I've tried downgrading ui-tooling dependency but nothing seems to work.
What is strange is that JetSnack project Preview is working, I've spent a day copying all the versions to my project but nothing seems to work, any ideas?
java.lang.ClassNotFoundException: android.view.OnBackInvokedCallback
at com.android.tools.idea.rendering.classloading.loaders.DelegatingClassLoader.findClass(DelegatingClassLoader.kt:81)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at com.android.tools.idea.rendering.classloading.loaders.DelegatingClassLoader.loadClass(DelegatingClassLoader.kt:65)
at androidx.compose.ui.tooling.ComposeViewAdapter$FakeOnBackPressedDispatcherOwner$1.<init>(ComposeViewAdapter.kt:738)
at androidx.compose.ui.tooling.ComposeViewAdapter.<init>(ComposeViewAdapter.kt:737)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:352)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:189)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:149)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:301)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:417)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:428)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:332)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965)
at android.view.LayoutInflater.inflate(LayoutInflater.java:663)
at android.view.LayoutInflater.inflate(LayoutInflater.java:505)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:361)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:436)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:736)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$7(RenderTask.java:892)
at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$2.run(RenderExecutor.kt:187)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
these are related dependencies from gradle, I'll be happy to provide more info if required:
implementation "androidx.core:core-ktx:1.7.0"
//current compose_version is 1.1.1
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.compose.ui:ui-tooling-data:$compose_version"
implementation "androidx.compose.runtime:runtime:$compose_version"
implementation "androidx.activity:activity-compose:1.6.0-alpha01"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.5.0-alpha05"
implementation "androidx.navigation:navigation-compose:2.5.0-alpha03"
implementation 'io.coil-kt:coil-compose:2.0.0-rc02'
CodePudding user response:
Had the same issue and I changed this dependency:
implementation "androidx.activity:activity-compose:1.3.1"
Found here: https://stackoverflow.com/a/68499790/3465420