Kotlin Multiplatform 项目的 iosMain 中的 Cocoapod 依赖项,cocoapod 未解决的参考

Cocoapod dependency in iosMain of a Kotlin Multiplatform project, cocoapod unresolved reference

我正在尝试围绕 AWS Amplify 创建一个包装器以用于我的项目。我的共享(公共)模块中有一个名为 Amplify 的模块。这里我在官方文档中integrated cocoapods as instructed。但是当我尝试从 iosMain 导入任何东西时,我不断得到 Unresolved reference: cocoapods.

我的项目结构如下

通用模块(共享)
|- 根模块
|- 其他功能
|- 放大包装模块

在根模块中我有

kotlin {
    ios {
        binaries {
            framework {
                baseName = "Framework"
                linkerOpts.add("-lsqlite3")
                export(project(":common:main"))
            }
        }
    }

以及放大模块中 cocoapods 的设置

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

plugins {
    id("multiplatform-setup") // this is from buildSrc, it adds the multiplatform plugin
    id("android-setup")
    id("org.jetbrains.kotlin.native.cocoapods")
    kotlin("plugin.serialization") version "1.5.10"
}

version = "1.0"


kotlin {
    sourceSets {
        named("commonMain") {
            dependencies {
            }
        }
    }

    cocoapods {
        summary = "Amplify wrapper for KMP project"
        homepage = "Link to a Kotlin/Native module homepage"
        frameworkName = "AmplifyKMP"

        pod("Amplify")
        pod("AmplifyPlugins/AWSCognitoAuthPlugin")
        pod("AmplifyPlugins/AWSPinpointAnalyticsPlugin")
    }
}

我的想法是我能够从 commonMain 代码公开我的包装器,这将调用 Amplify Android 和 Amplify IOS 库的实际实现。我的第一个问题是 cocoapods 未解决,其次是官方文档中的所有示例和 github 在主模块(在我的例子中是根模块)中都有 cocoapods 从他们导出框架的地方,我不确定我的方法还是可行的。

第一个问题很简单。您需要将 kotlin("native.cocoapods") 添加到 plugins 部分。

其次,子模块可以使用 cinterop 导入 pods 并使它们对依赖它们的模块可用吗?我没试过。理论上,cocoapods 插件应该能够将 pods 定义导入 kotlin。然而,cocoapods Kotlin gradle 插件(又名 kotlin("native.cocoapods"))将配置 ios 目标来创建一个框架。这可能会导致依赖配置出现问题。

在放大模块中,我没有看到您正在定义任何 iOS 目标,因此您可能需要这样做,但该配置将被 kotlin("native.cocoapods") 更改。您可能需要自己介入并修改它。您可以在 gradle 中介入并执行此操作,但我会准备花一些时间对其进行调整。

https://github.com/touchlab/KaMPKit/blob/main/shared/build.gradle.kts#L114