1

I am trying to integrate Snowplow to a Kotlin Multiplatform Project.

Android is working fine:

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

But integrating the iOS Cocoapod causes some troubles. I added the cocoapod plugin:

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

And the Snowlow pod:

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

Gradle sync results in the following error:

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

As I am Android developer I have basically zero knowledge about pods and their errors. I appreciate any hint towards a solution, as Google didn't help so far.

4ndro1d
  • 2,926
  • 7
  • 35
  • 65
  • I personally don't add dependencies with cocoapods plugin because it's not stable enough yet(huge compile time increacement). But jetbrains helps fast with such cocoapods issues on youtrack.jetbrains.com, usually it's because non standard cocoapods configuration(on the framework side). Create an issue there. – Phil Dukhov Jun 30 '21 at 02:18
  • How do you add dependencies then? – 4ndro1d Jun 30 '21 at 12:21
  • I create interfaces in kotlin part, implement members of those in swift - there I can use dependencies, and pass objects of these classes to shared module. Ofc it's much more code but build time costs more for me – Phil Dukhov Jun 30 '21 at 12:51

2 Answers2

1

I would say the important thing here is to meet all requirements listed in the documentation. I'm mostly concerned if your project configures

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

As I can see from the question, there is only pod() right now. Also, as the documentation and @Webfreak suggest, adding deploymentTarget might also help here.

Artyom Degtyarev
  • 2,704
  • 8
  • 23
  • 1
    Actually I had set the target to 8.0. (After error told me it automatically set the target to 8.0 as it was not set before). Looks like setting the target to 14 resolved the issue. – 4ndro1d Jul 05 '21 at 14:08
  • 1
    Gradle sync does work now, but I still cannot access any code from that dependencies within iOSMain(). anything else I am missing? Edit: Looks like it doesn't work with iOSMain hierarchy. Had to revert to Arm/X64 targets – 4ndro1d Jul 05 '21 at 14:34
  • Correct. Using cocoapods dependencies from `iosMain` source set requires [this](https://youtrack.jetbrains.com/issue/KT-41631) feature to be implemented. Separate Arm64/X64 targets would be easier to manage. You would also like to read about [the workaround](https://kotlinlang.org/docs/mobile/add-dependencies.html#workaround-to-enable-ide-support-for-the-shared-ios-source-set) we recommend. – Artyom Degtyarev Jul 06 '21 at 06:09
0

I believe you also need to specify path to the podfile and (not sure if required) deployment target like this:

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

Also try to manually run cocoapod gradle tasks podImport and podInstall

Simon
  • 1,657
  • 11
  • 16
  • I am writing a library, not an app. So adapting the path to iosArm64Main should do the job? Also I need to find out how to get/generate the Podfile – 4ndro1d Jul 03 '21 at 19:15
  • Even if you are writing a library, you need xcode workspace project. In order to use cocoapods in kotlin native project. You cannot create kotlin native project that uses cocoapod without counterpart xcodeworkspace project. You can create podfile by running a command pod init. – Simon Jul 04 '21 at 09:26
  • From the doc: >You can manage Pod dependencies directly in IntelliJ IDEA and enjoy all the additional features such as code highlighting and completion. You can build the whole Kotlin project with Gradle and not ever have to switch to Xcode. – 4ndro1d Jul 04 '21 at 15:51
  • Correct. But you still need a 'demo' iOS project where you test the solution (for example: run test ios app which uses your k/n library). This project's podfile is referred to in my original answer. – Simon Jul 05 '21 at 05:36
  • That will be the project I am including the generated iOS framework (our main App). But I cannot export any framework when gradle is not able to sync/build the Kotlin MPP. So I expect a solution for that error in the MPP – 4ndro1d Jul 05 '21 at 07:34