1

我创建了一个演示项目来将 cocoapods 集成到 KMM 项目中。我从官方网站上关注了这个链接。step 3重新导入项目时,我收到以下错误。

Project already has a CocoaPods dependency with name SDWebImage,之后我什至无法在 KMM 中导入这个库。

有人可以帮忙吗?

更新:添加build.gradle.kts

import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

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

// CocoaPods requires the podspec to have a version.
 version = "1.0"

kotlin {
    android()
    ios {
        cocoapods {
            // Configure fields required by CocoaPods.
            summary = "Some description for a Kotlin/Native module"
            homepage = "Link to a Kotlin/Native module homepage"

            pod("SDWebImage")

            // You can change the name of the produced framework.
            // By default, it is the name of the Gradle project.
            frameworkName = "shared"
        }
    }
    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation("com.google.android.material:material:1.2.1")
            }
        }
        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13")
            }
        }
        val iosMain by getting
        val iosTest by getting
    }
}

android {
    compileSdkVersion(29)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdkVersion(24)
        targetSdkVersion(29)
    }
}

val packForXcode by tasks.creating(Sync::class) {
    group = "build"
    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
    val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
    val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
    val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)
    val targetDir = File(buildDir, "xcode-frameworks")
    from({ framework.outputDirectory })
    into(targetDir)
}

tasks.getByName("build").dependsOn(packForXcode)
4

1 回答 1

1

当您使用 cocoapods 插件时,您不需要手动声明packForXcode目标,也许这就是问题所在。尝试删除后的所有内容val packForXcode

cocoapods部分应该在里面kotlin,而不是在里面ios

于 2021-03-30T03:59:28.093 回答