KMM构建在添加KMMBridge插件后失败,如果存在依赖。

huangapple go评论59阅读模式
英文:

KMM build fails after adding KMMBridge plugin, if dependencies exist

问题

我正在尝试创建一个使用KMMBridge发布到Cocoapods的KMM项目。这对于仅返回字符串的基本项目运行正常,但当添加依赖以进行HTTP请求或解析JSON时,它停止工作。

我遵循了开始使用Kotlin Multiplatform Mobile的指南,并在完成后开始将KMMBridge代码添加到Gradle脚本中。只需添加KMMBridge插件

id("co.touchlab.faktory.kmmbridge") version "0.3.7"

这会导致以下错误的构建失败:

Caused by: java.lang.IllegalArgumentException: This fat framework already has a binary for architecture `arm64` (shared for target `ios_arm64`)

项目可以在这里找到:https://github.com/ionel71089/KotlinMultiplatformSandbox

这是shared模块的build.gradle.kts文件:

val ktorVersion = "2.2.4"

version = "0.1"

plugins {
    kotlin("multiplatform")
    id("com.android.library")
    kotlin("plugin.serialization") version "1.8.20"
    kotlin("native.cocoapods")

    id("co.touchlab.faktory.kmmbridge") version "0.3.4" // breaks build
//    `maven-publish`
}

kotlin {
    android {
        compilations all {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
    }
    
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "shared"
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
                implementation("io.ktor:ktor-client-core:$ktorVersion")
                implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
                implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
            }
        }

        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
            }
        }

        val androidMain by getting {
            dependencies {
                implementation("io.ktor:ktor-client-android:$ktorVersion")
            }
        }
        val androidUnitTest by getting

        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting

        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
            dependencies {
                implementation("io.ktor:ktor-client-darwin:$ktorVersion")
            }
        }

        val iosX64Test by getting
        val iosArm64Test by getting
        val iosSimulatorArm64Test by getting

        val iosTest by creating {
            dependsOn(commonTest)
            iosX64Test.dependsOn(this)
            iosArm64Test.dependsOn(this)
            iosSimulatorArm64Test.dependsOn(this)
        }
    }

    cocoapods {
        summary = "KMMBridgeSampleKotlin"
        homepage = "https://touchlab.dev"
        ios.deploymentTarget = "13"
    }
}

android {
    namespace = "com.example.kotlinmultiplatformsandbox"
    compileSdk = 33
    defaultConfig {
        minSdk = 24
        targetSdk = 33
    }
}

/*
addGithubPackagesRepository()
kmmbridge {
    mavenPublishArtifacts()
    githubReleaseVersions()
    spm()
    cocoapods("git@github.com:ionel71089/PublicPodspecs.git")
    versionPrefix.set("0.8")
}
 */

**注意:**我也尝试将依赖项添加到一个简单的KMMBridge示例项目中,但也没有成功(https://github.com/ionel71089/KMMBridgeSampleKotlin)。

英文:

I'm trying to create a KMM project that publishes to Cocoapods using KMMBridge. This works fine for a basic project that only returns a strings, but when adding dependencies to make a http requests or parse json, it stops working.

I followed the Get started with Kotlin Multiplatform Mobile and after finishing, I started adding the KMMBridge code to the Gradle script. Just adding the KMMBridge plugin

id("co.touchlab.faktory.kmmbridge") version "0.3.7"

breaks the build with the following error:

Caused by: java.lang.IllegalArgumentException: This fat framework already has a binary for architecture `arm64` (shared for target `ios_arm64`)

Project can be found here: https://github.com/ionel71089/KotlinMultiplatformSandbox

Here is the build.gradle.kts file for the shared module:

val ktorVersion = "2.2.4"
version = "0.1"
plugins {
kotlin("multiplatform")
id("com.android.library")
kotlin("plugin.serialization") version "1.8.20"
kotlin("native.cocoapods")
id("co.touchlab.faktory.kmmbridge") version "0.3.4" // breaks build
//    `maven-publish`
}
kotlin {
android {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = "shared"
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
}
}
val androidMain by getting {
dependencies {
implementation("io.ktor:ktor-client-android:$ktorVersion")
}
}
val androidUnitTest by getting
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
dependencies {
implementation("io.ktor:ktor-client-darwin:$ktorVersion")
}
}
val iosX64Test by getting
val iosArm64Test by getting
val iosSimulatorArm64Test by getting
val iosTest by creating {
dependsOn(commonTest)
iosX64Test.dependsOn(this)
iosArm64Test.dependsOn(this)
iosSimulatorArm64Test.dependsOn(this)
}
}
cocoapods {
summary = "KMMBridgeSampleKotlin"
homepage = "https://touchlab.dev"
ios.deploymentTarget = "13"
}
}
android {
namespace = "com.example.kotlinmultiplatformsandbox"
compileSdk = 33
defaultConfig {
minSdk = 24
targetSdk = 33
}
}
/*
addGithubPackagesRepository()
kmmbridge {
mavenPublishArtifacts()
githubReleaseVersions()
spm()
cocoapods("git@github.com:ionel71089/PublicPodspecs.git")
versionPrefix.set("0.8")
}
*/

Note: I've also tried adding the dependencies to a trivial KMMBridge sample project, but that didn't work either (https://github.com/ionel71089/KMMBridgeSampleKotlin).

答案1

得分: 1

你重复了你的框架定义。请参阅KMMBridge故障排除文档:

https://kmmbridge.touchlab.co/docs/TROUBLESHOOTING#error-this-fat-framework-already-has-a-binary-for-architecture-x64-common-for-target-ios_x64-or-similar-for-arm

英文:

You're duplicating your framework definitions. See the KMMBridge Troubleshooting doc:

https://kmmbridge.touchlab.co/docs/TROUBLESHOOTING#error-this-fat-framework-already-has-a-binary-for-architecture-x64-common-for-target-ios_x64-or-similar-for-arm

huangapple
  • 本文由 发表于 2023年4月11日 16:37:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75983921.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定