4

I'm trying to setup a KMM module with Couchbase Lite as a platform dependency for both Android and iOS. I'm running into errors getting this to work with CocoaPods for iOS:

Exception in thread "main" java.lang.Error: /var/folders/pv/3_5xn0dd0v5bf6sxbfcsq_wr0000gn/T/7009311365357251921.m:1:22: error: expected ';' after module name
    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:507)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:265)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:73)
    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)

The generated 7009311365357251921.m file is not present at that path afterwards, which makes this difficult to debug.

build.gradle.kts:

plugins {
    kotlin("multiplatform") version "1.4.21"
    kotlin("native.cocoapods") version "1.4.21"
    id("com.android.library")
}
...
kotlin {
    android()
    ios()
    cocoapods {
        summary = "TBD"
        homepage = "TBD"
        ios.deploymentTarget = "9.0"
        pod("CouchbaseLite-Enterprise") {
            version = "~> 2.8.1"
        }
    }
    ...
}
...

I get a different error if I use the non-enterprise release. Same build.gradle.kts except with pod("CouchbaseLite"). I get the error:

Exception in thread "main" java.lang.IllegalArgumentException: 'CBLQueryMeta' is going to be declared twice
    at org.jetbrains.kotlin.native.interop.gen.KotlinFile.<init>(KotlinCodeModel.kt:257)
    at org.jetbrains.kotlin.native.interop.gen.StubIrBridgeBuilder$kotlinFile$1.<init>(StubIrBridgeBuilder.kt:44)
    at org.jetbrains.kotlin.native.interop.gen.StubIrBridgeBuilder.<init>(StubIrBridgeBuilder.kt:46)
    at org.jetbrains.kotlin.native.interop.gen.StubIrDriver.run(StubIrDriver.kt:122)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:315)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:73)
    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)

Both these pod specs compile without problem in an Xcode project. But Kotlin native seems to run into issues with them.

Update:

The pod("CouchbaseLite") error seems to be caused by having both a CBLQueryMeta and CBLQuery interface defined. There's a YouTrack issue for this. This error will likely still be a problem with CouchbaseLite-Enterprise, if the original error could be resolved.

Update 2:

If I remove the { version = "~> 2.8.1" } or put it in the function call directly pod("CouchbaseLite-Enterprise", "~> 2.8.1") I get a different error:

Exception in thread "main" java.lang.Error: /var/folders/pv/3_5xn0dd0v5bf6sxbfcsq_wr0000gn/T/6649487835163649080.m:1:9: fatal error: module 'CouchbaseLite_Enterprise' 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:507)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:265)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:73)
    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)

Update 3:

I filed a YouTrack issue for this. It seems this might have something to do with the dash - in the CocoaPod library name. There was an issue that's been closed that had a fix for this by changing the module name to replace the dash - with an underscore _, but the fix doesn't seem to be working.

Jeff Lockhart
  • 5,379
  • 4
  • 36
  • 51

1 Answers1

0

Depending on which version of the toolchain you're using, seems as if you're using the wrong syntax to specify the version. Try pod("CouchbaseLite-Enterprise", "~> 2.8.1") instead.

mss
  • 287
  • 4
  • 17
  • I did try this and received a different error. I'll update the question. – Jeff Lockhart Jan 13 '21 at 01:26
  • It's not clear why there would be a difference between the two, as the API allows for the version to be specified both ways. The [docs](https://kotlinlang.org/docs/reference/native/cocoapods.html) describe the first way I had it though. – Jeff Lockhart Jan 13 '21 at 01:35