KMM错误:这个API是ktor内部的,不应该使用.如有更改或删除,恕不另行通知



更新Xcode到13.0后,我无法运行使用Kotlin Multiplatform的iOS应用程序。
Command PhaseScriptExecution failed with a nonzero exit code构建失败,它说错误是:

任务:shared:compileKotlinIos FAILED
e:/Users…path…/KtorClient。kt:(134,17):这个API是ktor内部的,不应该使用。如有更改或删除,恕不另行通知。

我们在更新到Xcode 13后也有类似的错误,但它总是与共享KMM库,JDK等有关…此错误多次出现:
> Process ‘command ‘/Library/Java/JavaVirtualMachines/jdk-11.0.12.jdk/Contents/Home/bin/java’' finished with non-zero exit value 1

134 line ofKtorClient.kt:

override suspend fun createPassword(email: String, password: String): CreatePasswordResponse {
return client.post {
url {
path("v1", "user", "create_password")
body = LoginRequest(email, password)
}
headers {
/*134.line*/    append(HttpHeaders.ContentType, ContentType.Application.Json)
}
}
}

我们已经尝试删除XCWorkspace,Podfile.lock, pod文件夹,然后pod重新安装,删除衍生数据,没有任何帮助。

我们也尝试了不同版本的Ktor, JDK,没有任何帮助。

在网上找到的这个命令也没有帮助(他们说你应该在更新Xcode后运行它):

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

这是Ktor的一个已知问题,与Kotlin中的此修复有关。

文档是这样说的:

注意,公开append函数的StringValuesBuilder类被错误地标记为InternalAPI注释。这个问题将在v2.0.0中修复。作为一种解决方案,您可以添加@OptIn(InternalAPI::class)注释来显式地选择使用该API。

您可以在@OptIn(InternalAPI::class)中选择您的特定行,或者将其添加到您的共享模块build.gradle.kts中以对整个模块生效:

kotlin {
// ..
sourceSets {
all {
languageSettings.optIn("io.ktor.util.InternalAPI")
}
// ...
}
}