将 Snowplow 添加到 iOS 的 Kotlin 多平台项目

Adding Snowplow to Kotlin multiplatform project for iOS

我正在尝试将 Snowplow 集成到 Kotlin 多平台项目中。

Android 工作正常:

val androidMain by getting {
        dependencies {
            api("com.snowplowanalytics:snowplow-android-tracker:1.7.1")
        }
    }

但是集成 iOS Cocoapod 会带来一些麻烦。我添加了 cocoapod 插件:

plugins {
    kotlin("multiplatform") version "1.4.32"
}

还有 Snowlow 吊舱:

kotlin {
    iosX64()
    iosArm64()
    cocoapods {
        pod("SnowplowTracker") {
            version = "~> 2.1.1"
        }
    }
}

Gradle 同步导致以下错误:

Exception in thread "main" java.lang.Error: /var/folders/gv/rc4dmzjs3wj9kt4kr00nwhdw0000gn/T/2185483547857483783.m:1:9: fatal error: module 'SnowplowTracker' not found
    at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
    at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesASTFiles(ModuleSupport.kt:68)
    at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesInfo(ModuleSupport.kt:14)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.buildNativeLibrary(main.kt:506)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:264)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:74)
    at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
    at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
    at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:41)

Execution failed for task ':cinteropSnowplowTrackerIosArm64'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

因为我是 Android 开发人员,所以我对 pods 及其错误的了解基本上为零。感谢任何关于解决方案的提示,因为 Google 到目前为止没有帮助。

我相信您还需要指定 podfile 的路径和(不确定是否需要)部署目标,如下所示:

 cocoapods {
    ....
    podfile = project.file("../iosApp/Podfile")
    ios.deploymentTarget = "10.0"
 }

也尝试手动 运行 cocoapod gradle 任务 podImportpodInstall

我想说这里重要的是满足 the documentation 中列出的所有要求。我最关心的是你的项目是否配置

summary, homepage, and frameworkName of the Podspec file in the cocoapods block.
version is a version of the Gradle project.

正如我从问题中看到的,目前只有pod()。 此外,正如 documentation 和@Webfreak 所建议的那样,添加 deploymentTarget 可能也会有所帮助。