MatkovIvan / nav_cupcake

Multiplatform adaptation of Google's `basic-android-kotlin-compose-training-cupcake`
94 stars 6 forks source link

"Error: Task :composeApp:compileDevelopmentExecutableKotlinWasmJs FAILED - Missing Symbol androidx.annotation/MainThread #2

Closed ghost closed 6 months ago

ghost commented 6 months ago

'''

Task :composeApp:compileDevelopmentExecutableKotlinWasmJs FAILED e: Module "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel" has a reference to symbol androidx.annotation/MainThread.|(){}[0]. Neither the module itself nor its dependencies contain such declaration. '''

This could happen if the required dependency is missing in the project. Or if there is a dependency of "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel" that has a different version in the project than the version that "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel" was initially compiled with. Please check that the project configuration is correct and has consistent versions of all required dependencies.

I am trying to use viewModel with only wasmJs but having this error when I run the application please help me resolve this

this is my composeApp build.gradle.kts

import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig

plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.jetbrainsCompose)
}

kotlin {
    @OptIn(ExperimentalWasmDsl::class)
    wasmJs {
        moduleName = "composeApp"
        browser {
            commonWebpackConfig {
                outputFileName = "composeApp.js"
                devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
                    static = (static ?: mutableListOf()).apply {
                        // Serve sources to debug inside browser
                        add(project.projectDir.path)
                        add(project.projectDir.path + "/commonMain/")
                        add(project.projectDir.path + "/wasmJsMain/")
                    }
                }
            }
        }
        binaries.executable()
    }

    sourceSets {
        all {
            languageSettings {
                optIn("androidx.compose.material3.ExperimentalMaterial3Api")
                optIn("org.jetbrains.compose.resources.ExperimentalResourceApi")
            }
        }

        commonMain.dependencies {
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material3)
            implementation(compose.ui)
            implementation(compose.components.uiToolingPreview)
            implementation(compose.components.resources)
            implementation(projects.shared)
            implementation(projects.pdnsClient)
            implementation(libs.compottie)
            implementation(libs.bundles.koin.compose)
            implementation(libs.androidx.lifecycle.viewmodel.compose)
            implementation(libs.androidx.navigation.compose)
        }
    }
}

compose.experimental {
    web.application {}
}
MatkovIvan commented 6 months ago

I assume that you solved the issue. It would be great if you can post some details of what was wrong