问题描述
在我的 KMM 应用程序中,尝试通过协程 StateFlow
收集数据的状态,但它向我抛出此错误,有没有人知道是什么导致了这种情况发生
无法访问“kotlinx.coroutines.flow.Flow”,它是“kotlinx.coroutines.flow.StateFlow”的超类型。检查您的模块类路径是否缺少或冲突的依赖项
var response = viewmodel.events.authenticateUser(User(username = "",password = ""))
print(viewmodel.stateFlow.value) // When it tries the .value it throws this error
这是我的gradle文件
plugins {
kotlin("multiplatform")
id("com.android.library")
kotlin("plugin.serialization") version "1.4.31"
}
kotlin {
val ktorVersion = "1.4.0"
val serializationVersion = "1.0.0-RC"
val coroutinesVersion = "1.4.3-native-mt"
android()
ios {
binaries {
framework {
baseName = "shared"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.google.android.material:material:1.2.1")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependencies {
implementation("com.google.android.material:material:1.2.1")
implementation("com.github.bumptech.glide:glide:4.11.0")
implementation("com.github.bumptech.glide:compiler:4.11.0")
implementation("io.ktor:ktor-client-android:$ktorVersion")
}
}
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13")
}
}
val iosMain by getting {
dependencies {
implementation("io.ktor:ktor-client-ios:$ktorVersion")
}
}
val iosTest by getting
}
}
android {
compileSdkVersion(29)
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdkVersion(24)
targetSdkVersion(29)
}
}
val packForXcode by tasks.creating(Sync::class) {
group = "build"
val mode = System.getenv("CONfigURATION") ?: "DEBUG"
val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
val framework =
kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
inputs.property("mode",mode)
dependsOn(framework.linkTask)
val targetDir = File(buildDir,"xcode-frameworks")
from({ framework.outputDirectory })
into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)