we are currently gritting our teeth trying to add ...
# ios
u
we are currently gritting our teeth trying to add CouchbaseLite as a Cocoapods dependency in our shared module. To test the general flow, we also added AFNetworking, which works fine.
Copy code
pod("AFNetworking") {
   version = "~> 4.0.1"
}
pod("CouchbaseLite-Enterprise") {
   version = "~> 3.1.0"
}
Couchbase, on the other hand, is not found. We have already tried everything like xcFramework-linking, interopt-compiler-arguments,... but slowly we run out of ideas. And I have the feeling that we are missing something - do any of you have any ideas? (i evaluated the whole thing once in a test project, which can be found here: https://github.com/niggeulimann/kmp_podDependency/tree/develop) Thanks for ideas and suggestions!
a
Have you tried adding
moduleName = "CouchbaseLite"
? https://kotlinlang.org/docs/native-cocoapods.html#module-not-found
u
Hi Artem. Yes I have
a
Do you have any errors/warnings during build or gradle sync?
u
Beside the a gradle-version warning there is nothing
Copy code
w: Kotlin Multiplatform <-> Android Gradle Plugin compatibility issue: The applied Android Gradle Plugin version (8.0.1) is higher than the maximum known to the Kotlin Gradle Plugin. Tooling stability in such configuration isn't tested, please report encountered issues to <http://kotl.in/issue|kotl.in/issue>
Minimum supported Android Gradle Plugin version: 4.1
Maximum tested Android Gradle Plugin version: 7.4
To suppress this message add kotlin.mpp.androidGradlePluginCompatibility.nowarn=true to your gradle.properties
But I already tried to downgrade success
everything else seems to work
Copy code
> Task :shared:generateDefAFNetworking
> Task :shared:generateDummyFramework
> Task :shared:podspec UP-TO-DATE
> Task :shared:podGenIOS
> Task :shared:podSetupBuildAFNetworkingIphonesimulator
> Task :shared:podBuildAFNetworkingIphonesimulator
> Task :shared:cinteropAFNetworkingIosSimulatorArm64
> Task :shared:generateDefCouchbaseLite
> Task :shared:podSetupBuildCouchbaseLite-EnterpriseIphonesimulator
> Task :shared:podBuildCouchbaseLite-EnterpriseIphonesimulator
> Task :shared:cinteropCouchbaseLiteIosSimulatorArm64 UP-TO-DATE
But it is nowhere to be found
but it is there
r
Maybe it's not related, but I regularly have issues with cocoapods interop not showing up in IDE, and every time it doesn't fix itself because of some cache: there's the real problem, and then there's the cached problem which stays even if you did the right thing to fix it. The usual thing I have to do it to kill the Gradle daemon, but there's also IDE cache, build folder, .gradle, etc.
So when you don't really know what you're doing and try things, and realize the third time you try the exact same fix that it works but you didn't clear this or that specific cache previously…
a
everything else seems to work
Task sharedcinteropCouchbaseLiteIosSimulatorArm64 UP-TO-DATE
Can you please run
./gradlew :shared:cinteropCouchbaseLiteIosSimulatorArm64 --rerun-tasks
? UP-TO-DATE status may hide some useful info
u
yes, this failes:
Copy code
> Task :shared:cinteropCouchbaseLiteIosSimulatorArm64
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:44)
        at org.jetbrains.kotlin.native.interop.gen.StubIrDriver.run(StubIrDriver.kt:128)
        at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:342)
        at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLibSafe(main.kt:219)
        at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:80)
        at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
        at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:40)
        at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:62)

> Task :shared:cinteropCouchbaseLiteIosSimulatorArm64 FAILED
🤔 I have seen this before
r
(Again bitten by an evil cache 😄)
u
ok. After adding
Copy code
kotlin {
    targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>().all {
        compilations["main"].cinterops["CouchbaseLite"].extraOpts("-compiler-option", "-DCBLQueryMeta=CBLQueryMetaUnavailable")
    }
}
I got a successful build with
./gradlew :shared:cinteropCouchbaseLiteIosSimulatorArm64 --rerun-tasks
unfortunately the build still failed:
Copy code
> Task :shared:compileKotlinIosSimulatorArm64 FAILED
e: file:///Users/niggeulimann/work/customers/getslash/KotlinPlayground/PodTestApp/shared/src/iosMain/kotlin/de/getslash/pos_mobile/podtestapp/Platform.kt:5:18 Unresolved reference: CouchbaseLite

FAILURE: Build failed with an exception.
a
The package would be
CouchbaseLite_Enterprise
, same as pod name
You can add
packageName = "cocoapods.CouchbaseLite" to pod declaration
to make original package work
u
hm, like this?
Copy code
pod("CouchbaseLite-Enterprise") {
            moduleName = "CouchbaseLite"
            packageName = "cocoapods.CouchbaseLite"
            version = "~> 3.1.0"
        }
a
Yup
u
🥳 it works! thanks a lot!
so, the issue has been the duplicate CBLQueryMeta? And afterwards the mixed-up names?
a
Yes, seems like it
u
Copy code
Task :shared:cinteropCouchbaseLiteIosSimulatorArm64 UP-TO-DATE
is kind of misleading in that case
Copy code
Task :shared:cinteropCouchbaseLiteIosSimulatorArm64 STILL_BROKEN
would be nice 😉
Anyways: Thanks a lot - we were about to throw in the towel and inject the whole thing from the outside...
a
Agree, but you can’t have it with Gradle. The only option is to rerun the task each time after failure. But it may be a better choice in this case, we’ll think about it
u
As I know now, it’s fine. But it is really confusing. Thanks for your time and patience.
j
I just saw this thread. I experienced the same headache importing Couchbase Lite for my KMP library at first. Turns out because Kotlin's C interop generates a
ClassNameMeta
class for every class, it causes conflicts if there's already a class named both
Foo
and
FooMeta
. While the workaround in the YouTrack issue works, the only drawback is the class isn't usable from Kotlin.