在我的 KMM 应用程序中,试图通过协程收集数据的状态,StateFlow
但它向我抛出了这个错误,有谁知道是什么原因导致这种情况发生
无法访问“kotlinx.coroutines.flow.StateFlow”的超类型“kotlinx.coroutines.flow.Flow”。检查您的模块类路径是否存在缺失或冲突的依赖项
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)