stackich
stackich

Reputation: 5207

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

After updating Xcode to 13.0, I cannot run my iOS app which is using Kotlin Multiplatform.
Build fails with Command PhaseScriptExecution failed with a nonzero exit code, and it says that the error is:

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.

We have also had similar errors after updating to Xcode 13, but it is always something with shared KMM library, JDK etc... This error showed many times:
> Process ‘command ‘/Library/Java/JavaVirtualMachines/jdk-11.0.12.jdk/Contents/Home/bin/java’' finished with non-zero exit value 1

134 line of 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)
            }
        }
    }

We have tried deleting XCWorkspace, Podfile.lock, Pods folder, then pod reinstalling, deleting derived data, nothing helped.

We have also tried different versions of Ktor, JDK, nothing helped.

Also this command found on the Internet didnt help(they say you should run it after updating Xcode):

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

Upvotes: 4

Views: 1742

Answers (1)

Phil Dukhov
Phil Dukhov

Reputation: 87605

This is a known issue of Ktor, related to this fix in Kotlin.

Here's what documentation says:

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.

You can opt-in your specific line with @OptIn(InternalAPI::class), or add this in your shared module build.gradle.kts to take effect on the whole module:

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

Upvotes: 5

Related Questions