MacOS Kmp 无法安装 ktor 依赖
MacOS Kmp cannot install ktor dependency
使用 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 依赖项时,它构建得很好。我现在没有任何额外的构建 gradle 被修改,所以我知道我目前没有在任何额外的地方安装 ktor。我不明白为什么 ios 有效而 macos 失败。我读到 xcode 错误的方式似乎有一个重复的 ktor method/class?任何帮助将不胜感激!我也在这个 repo 之后进行了很多建模 https://github.com/joreilly/PeopleInSpace,我能看到的唯一主要区别是我仍在使用 cocoa pods 而另一个开发人员迁移到了 swift包管理器
根据the documentation,Ktor 的CIO 引擎是JVM-only。尝试使用 curl
一个:
val macosMain by getting {
dependencies {
implementation("io.ktor:ktor-client-curl:$ktor_version")
}
}
使用 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 依赖项时,它构建得很好。我现在没有任何额外的构建 gradle 被修改,所以我知道我目前没有在任何额外的地方安装 ktor。我不明白为什么 ios 有效而 macos 失败。我读到 xcode 错误的方式似乎有一个重复的 ktor method/class?任何帮助将不胜感激!我也在这个 repo 之后进行了很多建模 https://github.com/joreilly/PeopleInSpace,我能看到的唯一主要区别是我仍在使用 cocoa pods 而另一个开发人员迁移到了 swift包管理器
根据the documentation,Ktor 的CIO 引擎是JVM-only。尝试使用 curl
一个:
val macosMain by getting {
dependencies {
implementation("io.ktor:ktor-client-curl:$ktor_version")
}
}