我无法让 Ktor 在 KMM 项目中工作,我只是Unresolved reference: HttpClient在尝试引用任何 Ktor 类时收到错误。如果我尝试手动添加 ktor 导入,它会显示Unresolved reference io. 其他依赖项(如Kermit解析良好)似乎只是 Ktor 存在问题。这是我重现的简单步骤:
在 Android Studio 中(我尝试过 4.1.3 和 4.2 Beta 6),我转到文件 -> 新建 -> KMM 应用程序。
在共享模块 build.gradle.kts 中,我添加了 ktor 客户端的依赖项:
val commonMain by getting {
dependencies {
implementation("io.ktor:ktor-client-core:1.5.2")
}
}
Run Code Online (Sandbox Code Playgroud)
Greeting中所述:class Greeting {
val httpClient: HttpClient = HttpClient()
fun greeting(): String {
return "Hello, ${Platform().platform}!"
}
}
Run Code Online (Sandbox Code Playgroud)
我明白了Unresolved reference: HttpClient …
我需要为 iOS 和 Android 构建一个应用程序。
重新启动 Android Studio 后出现此错误。
Kotlin Multiplatform Mobile 插件问题
Kotlin Multiplatform Mobile 插件应该只适用于 macOS
我正在使用 Windows 机器。
请告诉我,如果有任何解决此问题的方法。