Search code examples
kotlin-multiplatform

Failed to resolve Kotlin library io.ktor-ktor-client-logging


I am trying to write a simple multiplatform library for Android and iOS. My dependencies are:

sourceSets {
    val commonMain by getting {
        dependencies {
            implementation("io.ktor:ktor-client-core:1.6.3")
            implementation("io.ktor:ktor-client-logging:1.6.3")
            implementation("io.ktor:ktor-client-serialization:1.6.3")     
            implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2")
        }
    }
    val commonTest by getting {
        dependencies {
            implementation(kotlin("test"))
        }
    }
    val androidMain by getting {
        dependencies {
            rootProject
            //implementation("com.google.android.material:material:1.4.0")
            implementation("io.ktor:ktor-client-okhttp:1.6.3")
        }
    }
    val androidTest by getting {
        dependencies {
            implementation("junit:junit:4.13")
        }
    }
    val iosArm64Main by getting {
        dependencies {
            implementation("io.ktor:ktor-client-ios:1.6.3")
        }
    }
    val iosArm64Test by getting
}

I am getting this error when building:

java.lang.IllegalStateException: e: Failed to resolve Kotlin library: /Users/????/IdeaProjects/????/build/kotlinSourceSetMetadata/commonMain/io.ktor-ktor-client-logging/io.ktor-ktor-client-logging-commonMain.klib

even though I see package in build/kotlinSourceSetMetaData folder.

When I set kotlin.mpp.enableGranularSourceSetsMetadata=false in gradle.properties error changes to:

    > Task :compileKotlinIosArm64
w: skipping /Users/????/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-client-logging-iosarm64/1.6.3/374d82df9cd22c5960ffc1eecc6ec45f3101031/ktor-client-logging.klib. Incompatible abi version. The current default is '1.4.2', found '1.5.0'. The library produced by 1.5.20 compiler
e: Could not find "/Users/????/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-client-logging-iosarm64/1.6.3/374d82df9cd22c5960ffc1eecc6ec45f3101031/ktor-client-logging.klib" in [/Users/????/IdeaProjects/????, /Users/????/.konan/klib, /Users/????/.konan/kotlin-native-prebuilt-macos-1.5.10/klib/common, /Users/????/.konan/kotlin-native-prebuilt-macos-1.5.10/klib/platform/ios_arm64]

Solution

  • The latter error suggests you to synchronize the Kotlin version you're using and the Ktor version. Check the Recommended kotlinx library versions for details. Probably, you will need to change the Kotlin to 1.5.30, or downgrade the Ktor 1.5.4.

    Please comment below with the result. I'll update this answer if something will be still wrong.