如何在 Kotlin 多平台(iOS、Web、桌面、Android)上
import androidx.lifecycle.viewmodel.compose.viewModel
?
尝试:
[versions]
androidx-activityCompose = "1.10.0-alpha02"
androidx-compose-runtime = "1.8.0-alpha03"
androidx-lifecycle-viewmodel = "2.9.0-alpha04"
lifecycleViewmodel = "2.9.0-dev1873"
[libraries]
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle-viewmodel" }
androidx-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "androidx-compose-runtime" }
jetbrains-lifecycle-viewmodel = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel", version.ref = "lifecycleViewmodel" }
lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel", version.ref = "androidx-lifecycle-viewmodel" }
然后在
kotlin.sourceSets.ommonMain.dependencies
的build.gradle
中:
runtimeOnly(libs.androidx.runtime)
runtimeOnly(libs.androidx.lifecycle.viewmodel.compose)
runtimeOnly(libs.lifecycle.viewmodel)
implementation(libs.jetbrains.lifecycle.viewmodel)
不幸的是,这不起作用:
您的依赖项似乎有拼写错误。 build.gradle 的“kotlin.sourceSets.ommonMain.dependencies”