Zoltan Demant
02/28/2024, 9:18 AMimplementation(libs.coroutines.swing)
for my jvm/desktop target, but at runtime I run into issues relating to Module with the Main dispatcher had failed to initialize
and it also mentions Caused by: java.lang.NoClassDefFoundError: android/os/Looper
which seems odd given that its a desktop application. Any hints or ideas as to what might be wrong? Ive read about proguard for desktop potentially removing the dispatcher, but disabling proguard also does not seem to make a difference.Sam
02/28/2024, 9:22 AMNoClassDefFoundError
? It'd be interesting to see where it's coming from. I'm wondering if maybe the kotlinx-coroutines-android dependency has made its way onto the classpath from somewhere else.Zoltan Demant
02/28/2024, 9:27 AMSuppressed: java.lang.IllegalStateException: Module with the Main dispatcher had failed to initialize. For tests Dispatchers.setMain from kotlinx-coroutines-test module can be used
at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.missing(MainDispatchers.kt:111)
at kotlinx.coroutines.internal.MissingMainCoroutineDispatcher.isDispatchNeeded(MainDispatchers.kt:92)
at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:315)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:26)
... 235 more
Caused by: java.lang.NoClassDefFoundError: android/os/Looper
at kotlinx.coroutines.android.AndroidDispatcherFactory.createDispatcher(HandlerDispatcher.kt:51)
at kotlinx.coroutines.internal.MainDispatchersKt.tryCreateDispatcher(MainDispatchers.kt:53)
at kotlinx.coroutines.internal.MainDispatcherLoader.loadMainDispatcher(MainDispatchers.kt:34)
at kotlinx.coroutines.internal.MainDispatcherLoader.<clinit>(MainDispatchers.kt:18)
at kotlinx.coroutines.Dispatchers.getMain(Dispatchers.kt:20)
at androidx.compose.ui.text.platform.DispatcherKt.<clinit>(Dispatcher.kt:33)
at androidx.compose.ui.text.font.FontListFontFamilyTypefaceAdapter.<init>(FontListFontFamilyTypefaceAdapter.kt:58)
at androidx.compose.ui.text.font.FontListFontFamilyTypefaceAdapter.<init>(FontListFontFamilyTypefaceAdapter.kt:50)
at androidx.compose.ui.text.font.FontFamilyResolverImpl.<init>(FontFamilyResolver.kt:31)
at androidx.compose.ui.text.font.FontFamilyResolver_sikioKt.createFontFamilyResolver(FontFamilyResolver.skiko.kt:78)
at androidx.compose.ui.text.platform.FontLoader.<init>(PlatformFont.skiko.kt:176)
at androidx.compose.ui.node.RootNodeOwner$OwnerImpl.<init>(RootNodeOwner.skiko.kt:267)
at androidx.compose.ui.node.RootNodeOwner.<init>(RootNodeOwner.skiko.kt:118)
at androidx.compose.ui.scene.MultiLayerComposeSceneImpl.<init>(MultiLayerComposeScene.skiko.kt:114)
at androidx.compose.ui.scene.MultiLayerComposeScene_skikoKt.MultiLayerComposeScene(MultiLayerComposeScene.skiko.kt:93)
at androidx.compose.ui.scene.MultiLayerComposeScene_skikoKt.MultiLayerComposeScene$default(MultiLayerComposeScene.skiko.kt:86)
at androidx.compose.ui.scene.ComposeContainer.createComposeScene(ComposeContainer.desktop.kt:248)
at androidx.compose.ui.scene.ComposeContainer.access$createComposeScene(ComposeContainer.desktop.kt:67)
at androidx.compose.ui.scene.ComposeContainer$mediator$3.invoke(ComposeContainer.desktop.kt:119)
at androidx.compose.ui.scene.ComposeContainer$mediator$3.invoke(ComposeContainer.desktop.kt:119)
at androidx.compose.ui.scene.ComposeSceneMediator$scene$2.invoke(ComposeSceneMediator.desktop.kt:193)
at androidx.compose.ui.scene.ComposeSceneMediator$scene$2.invoke(ComposeSceneMediator.desktop.kt:193)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at androidx.compose.ui.scene.ComposeSceneMediator.getScene(ComposeSceneMediator.desktop.kt:193)
at androidx.compose.ui.scene.ComposeSceneMediator.setCompositionLocalContext(ComposeSceneMediator.desktop.kt:197)
at androidx.compose.ui.scene.ComposeContainer.setCompositionLocalContext(ComposeContainer.desktop.kt:129)
at androidx.compose.ui.awt.ComposeWindowPanel.setCompositionLocalContext(ComposeWindowPanel.desktop.kt:70)
at androidx.compose.ui.awt.ComposeWindow.setCompositionLocalContext(ComposeWindow.desktop.kt:114)
at androidx.compose.ui.window.Window_desktopKt$Window$10.invoke(Window.desktop.kt:411)
at androidx.compose.ui.window.Window_desktopKt$Window$10.invoke(Window.desktop.kt:406)
at androidx.compose.ui.window.AwtWindow_desktopKt$AwtWindow$2.invoke(AwtWindow.desktop.kt:70)
at androidx.compose.ui.window.AwtWindow_desktopKt$AwtWindow$2.invoke(AwtWindow.desktop.kt:69)
at androidx.compose.runtime.DisposableEffectImpl.onRemembered(Effects.kt:82)
at androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers(Composition.kt:1295)
at androidx.compose.runtime.CompositionImpl.applyChangesInLocked(Composition.kt:984)
at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:1005)
at androidx.compose.runtime.Recomposer.composeInitial$runtime(Recomposer.kt:1099)
at androidx.compose.runtime.CompositionImpl.composeInitial(Composition.kt:633)
at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:619)
at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2.invokeSuspend(Application.desktop.kt:219)
... 15 more
Caused by: java.lang.ClassNotFoundException: android.os.Looper
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
... 55 more
Caused by: java.lang.NoClassDefFoundError: android/os/Build$VERSION
at kotlinx.coroutines.android.AndroidExceptionPreHandler.handleException(AndroidExceptionPreHandler.kt:43)
at kotlinx.coroutines.internal.CoroutineExceptionHandlerImpl_commonKt.handleUncaughtCoroutineException(CoroutineExceptionHandlerImpl.common.kt:34)
... 244 more
Caused by: java.lang.ClassNotFoundException: android.os.Build$VERSION
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
... 246 more
Sam
02/28/2024, 9:35 AMkotlinx.coroutines.android.AndroidDispatcherFactory
part sure makes it look like kotlinx-coroutines-android
is on the classpathSam
02/28/2024, 9:35 AM./gradlew dependencyInsight --dependency=kotlinx-coroutines-android
Zoltan Demant
02/28/2024, 10:58 AMZoltan Demant
02/28/2024, 10:58 AMZoltan Demant
02/28/2024, 11:02 AMkotlinx-coroutines-play-services:1.8.0
depends on the kotlinx-coroutines-bom:1.8.0
, which includes kotlinx-coroutines-android:1.8.0
. This BOM (Bill of Materials) file specifies versions for all kotlinx-coroutines libraries consistently to avoid version conflicts.Zoltan Demant
02/28/2024, 11:03 AMSam
02/28/2024, 11:09 AMSam
02/28/2024, 11:11 AMcoroutines-android
in the android-specific parts of your application. As you said, coroutines-core
is all you need in common code.Zoltan Demant
02/28/2024, 11:12 AMSam
02/28/2024, 11:14 AMSam
02/28/2024, 11:14 AMZoltan Demant
02/28/2024, 11:14 AMSam
02/28/2024, 11:16 AMZoltan Demant
02/28/2024, 11:17 AMZoltan Demant
02/28/2024, 11:19 AMZoltan Demant
02/28/2024, 11:19 AMSam
02/28/2024, 11:20 AMZoltan Demant
02/28/2024, 11:27 AMimage
module with a dependency on coil
(the KMP versions) and for jvmMain includes coroutines-swing. I can run that project just fine, and previously when I would pull it into my other project (the one thats failing now) it would work just fine. So Im guessing its something in this project specifically, but its a large project 😅Sam
02/28/2024, 11:30 AMcoroutines-swing
in a library. Typically you would only need to include that as a runtime dependency when you're actually deploying an application.Sam
02/28/2024, 11:30 AMcoroutines-android
.Zoltan Demant
02/28/2024, 11:34 AMSam
02/28/2024, 11:37 AMSam
02/28/2024, 11:38 AMZoltan Demant
02/28/2024, 11:40 AMAll you need is to make sure the dispatcher is present at runtime.Isnt that what Im doing by specifying it as a dependency in my library? Fwiw, both projects are KMP based.
Zoltan Demant
02/28/2024, 11:41 AMdependencyInsight
; both core, jvm, etc, are present (along with android).Sam
02/28/2024, 11:47 AMZoltan Demant
02/28/2024, 12:32 PMZoltan Demant
02/28/2024, 12:44 PMZoltan Demant
02/28/2024, 12:45 PMZoltan Demant
02/28/2024, 12:45 PMZoltan Demant
02/28/2024, 12:46 PM