badoo / MVIKotlin

Extendable MVI framework for Kotlin Multiplatform with powerful debugging tools (logging and time travel), inspired by Badoo MVICore library
https://arkivanov.github.io/MVIKotlin
Apache License 2.0
828 stars 64 forks source link

Error: java.lang.NoClassDefFoundError: android/os/Looper in: DefaultStore.kt:31 #180

Closed Shabinder closed 3 years ago

Shabinder commented 3 years ago

Caused by: java.lang.NoClassDefFoundError: android/os/Looper at kotlinx.coroutines.android.AndroidDispatcherFactory.createDispatcher(HandlerDispatcher.kt:55) at kotlinx.coroutines.android.AndroidDispatcherFactory.createDispatcher(HandlerDispatcher.kt:52) at kotlinx.coroutines.internal.MainDispatchersKt.tryCreateDispatcher(MainDispatchers.kt:57) at kotlinx.coroutines.internal.MainDispatcherLoader.loadMainDispatcher(MainDispatchers.kt:38) at kotlinx.coroutines.internal.MainDispatcherLoader.(MainDispatchers.kt:22) at kotlinx.coroutines.Dispatchers.getMain(Dispatchers.kt:58) at com.arkivanov.mvikotlin.extensions.coroutines.SuspendExecutor.(SuspendExecutor.kt:23) at com.shabinder.common.main.store.SpotiFlyerMainStoreProvider$ExecutorImpl.(SpotiFlyerMainStoreProvider.kt:57) at com.shabinder.common.main.store.SpotiFlyerMainStoreProvider$provide$1$1.invoke(SpotiFlyerMainStoreProvider.kt) at com.shabinder.common.main.store.SpotiFlyerMainStoreProvider$provide$1$1.invoke(SpotiFlyerMainStoreProvider.kt) at com.arkivanov.mvikotlin.main.store.DefaultStore.(DefaultStore.kt:31) ... 143 more

image

My Store Creator: image

My Suspend Executor: image

All methods like openPlatform,etc are just expect/actual empty blocks image

PS: 1.All Implementations Are very similar to as shown in todo app , except these are coroutine/suspend instead of Reaktive 2.Crash is in Desktop only , same implementation works good in Android app(All Code is Common/Shared module)

arkivanov commented 3 years ago

@Shabinder Could you please also provide build.gradle of the shared module and of the desktop app module?

Shabinder commented 3 years ago

Desktop Build Gradle:

import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
    kotlin("multiplatform")
    id("org.jetbrains.compose")
}

group = "com.shabinder"
version = Versions.versionName

kotlin {
    jvm {
        compilations.all {
            kotlinOptions.jvmTarget = "11"
        }
    }
    sourceSets {
        val jvmMain by getting {
            dependencies {
                implementation(compose.desktop.currentOs)
                implementation(project(":common:database"))
                implementation(project(":common:dependency-injection"))
                implementation(project(":common:compose-ui"))
                implementation(Decompose.decompose)
                implementation(Decompose.extensionsCompose)
                implementation(MVIKotlin.mvikotlin)
                implementation(MVIKotlin.mvikotlinMain)
            }
        }
        val jvmTest by getting
    }
}

compose.desktop {
    application {
        mainClass = "MainKt"
        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "SpotiFlyer"
        }
    }
}

Common Module:

import org.jetbrains.compose.compose

plugins {
    id("multiplatform-compose-setup")
    id("android-setup")
    id("kotlin-parcelize")
}

kotlin {
    sourceSets {
        commonMain {
            dependencies {
                implementation(compose.materialIconsExtended)
                //implementation("org.jetbrains.compose.material:material-icons-extended:0.3.0-build150")
                implementation(project(":common:dependency-injection"))
                //implementation("com.alialbaali.kamel:kamel-image:0.0.7")
                implementation(project(":common:data-models"))
                implementation(project(":common:database"))
                implementation(SqlDelight.coroutineExtensions)
                implementation(MVIKotlin.coroutines)
                implementation(MVIKotlin.mvikotlin)
                implementation(Decompose.decompose)
                implementation(Decompose.extensionsCompose)

                //Coil-Image Loading
                Versions.coilVersion.let{
                    implementation("dev.chrisbanes.accompanist:accompanist-coil:$it")
                    implementation("dev.chrisbanes.accompanist:accompanist-insets:$it")
                }
            }
        }
    }
}
arkivanov commented 3 years ago

It is a very weird crash. Am I right that the crash in on Desktop only? For some reason it uses Dispatchers.Main for Android. It is hard to get more details without a reproducer. Would you be able to provide it?

Shabinder commented 3 years ago

Yup , its desktop only, what do you mean by reproducer

arkivanov commented 3 years ago

@Shabinder By reproducer I mean a project that I could debug.

Shabinder commented 3 years ago

@arkivanov I have invited you as a collaborator ,so that you may have access to private repo's Project , which might help you in debugging. image

arkivanov commented 3 years ago

@Shabinder Thanks for the reproducer! So the is issue is because you added accompanist libraries to the commonMain source set. These libraries are Android only, they can't be used in common code.

Shabinder commented 3 years ago

oops.., Thanks @arkivanov removing accompanist libs did the trick. I forgot to remove them while I was experimenting.