【问题标题】:MacOS Kmp cannot install ktor dependencyMacOS Kmp 无法安装 ktor 依赖
【发布时间】:2021-06-30 01:36:45
【问题描述】:

使用 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 for 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 依赖项时,它构建得很好。我现在没有任何额外的构建 gradle 被修改,所以我知道我目前没有在任何额外的地方安装 ktor。我不明白为什么 ios 工作而 macos 失败。我阅读那个xcode错误的方式似乎有一个重复的ktor方法/类?任何帮助将不胜感激!在这个 repo 之后,我也做了很多建模 https://github.com/joreilly/PeopleInSpace,我能看到的唯一主要区别是我仍在使用可可豆荚,而其他开发人员迁移到了 swift 包管理器

【问题讨论】:

    标签: xcode kotlin kotlin-multiplatform


    【解决方案1】:

    根据the documentation,Ktor 的 CIO 引擎是 JVM-only。尝试使用curl 一:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-06
      • 2020-05-26
      • 1970-01-01
      • 2021-05-29
      • 2018-09-11
      • 2018-05-30
      • 1970-01-01
      相关资源
      最近更新 更多