macOS Kmp не может установить зависимость ktor

#xcode #kotlin #kotlin-multiplatform

Вопрос:

Работая с Kotlin KMP и ориентируясь на macos, я испытываю проблемы с установкой зависимости ktor.

Вот мой общий файл модуля gradle

 plugins {
    kotlin("multiplatform")
    id("kotlinx-serialization")
    kotlin("native.cocoapods")
    id("com.android.library")
}

version = "1.0"

kotlin {
    android()
    jvm()

    val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
        if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
            ::iosArm64
        else
            ::iosX64

    iosTarget("ios") {}
    macosX64("macos")

    cocoapods {
        summary = "Some description for the Shared Module"
        homepage = "Link to the Shared Module homepage"
        // ios.deploymentTarget = AppleSdk.iosDeploymentTarget
        // osx.deploymentTarget = AppleSdk.osxDeploymentTarget
        frameworkName = "shared"
    }
    
    sourceSets {
        val commonMain by getting {
            dependencies {
                // ktor dependencies needs to use old coroutine version
                // https://youtrack.jetbrains.com/issue/KT-46697
                implementation(Kotlinx.coroutineCore)

                // Koin
                implementation(Koin.core)
                implementation(Koin.test)

                // Ktor
                implementation(Ktor.clientCore)
                implementation(Ktor.clientJson)
                implementation(Ktor.clientLogging)
                implementation(Ktor.clientSerialization)

                // serialization
                implementation(Kotlinx.serializationCore)
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation(Ktor.clientAndroid)
            }
        }
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation(Test.junit)
            }
        }
        val iosMain by getting {
            dependencies {
                // "io.ktor:ktor-client-ios:1.6.0"
                implementation(Ktor.clientIos)
            }
        }
        val iosTest by getting
        val jvmMain by getting {
            dependencies {
                implementation(Ktor.clientJvm)
            }
        }
        val jvmTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation(Test.junit)
            }
        }
        val macosMain by getting {
            dependencies {
                // "io.ktor:ktor-client-cio:1.6.0"
                implementation(Ktor.clientCio)
            }
        }
        val macosTest by getting
    }
}
 

Мое решение построено в Android studio, и я могу запустить свое решение в xcode для ios. Однако, когда я добираюсь до цели macos, я получаю эту ошибку в xcode:

 duplicate symbol '_kclass:io.ktor.network.sockets.SocketTimeoutException' in:
    {redacted}/shared/build/cocoapods/framework/shared.framework/shared(result.o)
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
 

Когда я удаляю зависимость macos ktor, она строится просто отлично. У меня нет никаких дополнительных градаций сборки, которые были бы изменены прямо сейчас, поэтому я знаю, что в настоящее время я не устанавливаю ktor в каких-либо дополнительных местах. Я не понимаю, почему ios работает, а macos терпит неудачу. Я так прочитал эту ошибку xcode, что кажется, что есть дубликат метода/класса ktor? Любая помощь будет очень признательна! Я также много моделирую после этого репо https://github.com/joreilly/PeopleInSpace и единственное существенное отличие, которое я вижу, заключается в том, что я все еще использую какао-бобы, а другие разработчики перешли на swift package manager

Ответ №1:

Согласно документации, CIO-движок Ktor предназначен только для JVM. Попробуйте использовать curl один:

 val macosMain by getting {
            dependencies {
                implementation("io.ktor:ktor-client-curl:$ktor_version") 
            }
        }