相关疑难解决方法(0)

将 Ktor 添加到 Kotlin Multiplatform Mobile 导致未解析的参考:HttpClient

我无法让 Ktor 在 KMM 项目中工作,我只是Unresolved reference: HttpClient在尝试引用任何 Ktor 类时收到错误。如果我尝试手动添加 ktor 导入,它会显示Unresolved reference io. 其他依赖项(如Kermit解析良好)似乎只是 Ktor 存在问题。这是我重现的简单步骤:

在此输入图像描述

  1. 在 Android Studio 中(我尝试过 4.1.3 和 4.2 Beta 6),我转到文件 -> 新建 -> KMM 应用程序。

  2. 在共享模块 build.gradle.kts 中,我添加了 ktor 客户端的依赖项:

val commonMain by getting {
        dependencies {
            implementation("io.ktor:ktor-client-core:1.5.2")
        }
     }
Run Code Online (Sandbox Code Playgroud)
  1. 在commonMain 的类中,我尝试创建一个 HttpClient,就像 Ktor 文档https://kotlinlang.org/docs/mobile/use-ktor-for-networking.html#select-an-engineGreeting中所述:
class Greeting {
    val httpClient: HttpClient = HttpClient()

    fun greeting(): String {
        return "Hello, ${Platform().platform}!"
    }
}
Run Code Online (Sandbox Code Playgroud)

我明白了Unresolved reference: HttpClient …

android gradle android-studio ktor kmm

6
推荐指数
1
解决办法
3035
查看次数

KMM 是否适用于 Android Studio - Windows 版本

我需要为 iOS 和 Android 构建一个应用程序。
重新启动 Android Studio 后出现此错误。

Kotlin Multiplatform Mobile 插件问题
Kotlin Multiplatform Mobile 插件应该只适用于 macOS

我正在使用 Windows 机器。
请告诉我,如果有任何解决此问题的方法。

windows android-studio kotlin-multiplatform kmm

3
推荐指数
1
解决办法
968
查看次数