KMM error: This API is internal in ktor and should not be used. It could be removed or changed without notice

KMM error: This API is internal in ktor and should not be used. It could be removed or changed without notice

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

Task :shared:compileKotlinIos FAILED
e: /Users...path.../KtorClient.kt: (134, 17): This API is internal in ktor and should not be used. It could be removed or changed without notice.

更新到 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 行KtorClient.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)
            }
        }
    }

我们尝试删除 XCWorkspacePodfile.lock、Pods 文件夹,然后重新安装 pod,删除派生数据,但没有任何帮助。

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

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

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

这是 Kotlin 中的 known issue of Ktor, related to this fix

documentation 是这样说的:

Note that the StringValuesBuilder class that exposes the append function is incorrectly marked with the InternalAPI annotation. This issue will be fixed in v2.0.0. As a workaround, you can add the @OptIn(InternalAPI::class) annotation to explicitly opt-in to use this API.

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

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