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

pkbketx9  于 2023-04-12  发布在  其他
关注(0)|答案(1)|浏览(183)

我正在尝试创建一个KMM项目,它使用KMMBridge发布到Cocoapods。这对于一个只返回字符串的基本项目来说很好,但是当添加依赖项以发出http请求或解析json时,它停止工作。
我按照Get started with Kotlin Multiplatform Mobile进行操作,完成后,我开始将KMMBridge代码添加到Gradle脚本中。
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)。

0md85ypi

0md85ypi1#

您正在复制框架定义。请参阅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

相关问题