Hi everyone! Is there some up-to-date guide on ho...
# multiplatform
m
Hi everyone! Is there some up-to-date guide on how to use a Cocoapod in the iOS part of a shared module? Following this isn't even quite possible since apparently the syntax for pod() changed since it's creation. And if I extrapolate the instructions and simply add
Copy code
pod("AFNetworking")
to the cocoapods section in build.gradle.kts, I get
Copy code
> Task :shared:cinteropAFNetworkingIosArm64 FAILED
Exception in thread "main" java.lang.Error: /var/folders/4g/3s9scp9d5593dphx7n_7nhk40000gn/T/tmp1272859169392324213.m:1:9: fatal error: module 'AFNetworking' not found
I'm trying this in an KMMApplication template from AndroidStudio 4.1.1 running Kotlin Plugin 1.4.21-release-Studio4.1.1, in which I've only modified build.gradle.kts to add
Copy code
kotlin("native.cocoapods")
to the plugins, changed the
Copy code
ios {
…
}
block to
Copy code
ios()
to get rid of the
Copy code
Caused by: java.lang.IllegalArgumentException: Cannot create binary debugFramework: binary with such a name already exists
error that appears when adding the Cocoapods plugin and added this
Copy code
cocoapods {
        pod("AFNetworking")
}
section. Am I missing something?
k
I would maybe try specifying version. The config error is
module 'AFNetworking' not found
. It's configured, but not finding that module for whatever reason. I'd also maybe try to build a regular iOS app in xcode with cocoapods to make sure that's working.
Played around with this a bit. Not really sure what's happening there. Seeing the same.
m
Hey Kevin, thanks for your input. I made sure to try this, specifying
Copy code
pod("AFNetworking", "~> 4.0")
as the dependency. That didn't change anything for me. At the same time, if I'm adding the same dependancy to a regular iOS app, it is indeed working correctly.
k
Yeah, I did the same. Not sure what's going on with it.
j
version
,
summary
and
homepage
are required as well:
Copy code
...
version = "1.0"

kotlin {
  ...
  cocoapods {
    summary = "Something"
    homepage = "<http://example.com|example.com>"
    pod("AFNetworking")
  }
}
k
Version can also come from the project version. I tried with a proper config and was still getting the issue.
j
I tested and worked for me.
m
Thank for for the suggestion, Jeff. I've just tried that and unfortunately, I'm still getting the issue as well.
f
Try changing
iosMain
folder to target-specific source sets(
iosX64Main
iosArm64Main
, etc). Code comletion is missing in
iosMain
but compilation should work fine. https://youtrack.jetbrains.com/issue/KT-42319#focus=Comments-27-4417756.0-0
m
Hey Suleyman, thanks for the input. I tried renaming the
iosMain
folder in my
shared
Module to
iosArm64Main
and created a symlink to that named
iosX64Main
, so it now looks like attached. Unfortunately, that doesn't seem to help either. I've tried to open the example project referenced in YouTrack, but that doesn't work for me (even after removing the outdated version numbers of the specified plugins, the whole kotlin() section in
build.gradle.kts
remains red).
c
AFNetworking
works for me but I see this error when I try to use some other dependencies like
(CouchbaseLite-Enterprise)
. I'm using AS Canary version, so in my root build.gradle I have;
Copy code
classpath 'com.android.tools.build:gradle:7.0.0-alpha03'

 // Touchlab build errors fails silently, making it hard to debug
 //classpath 'co.touchlab:kotlinnativecocoapods:0.12'
In my shared module build.gradle.kts I have the following;
Copy code
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("org.jetbrains.kotlin.native.cocoapods")
}

cocoapods {
        summary = "..."
        homepage = "..."
        ios.deploymentTarget = "13.5"
        pod("AFNetworking")
        pod("Masonry")
       
    }
My project setup is still the just
Copy code
ProjectName
--app
--shared
  --src
    --androidMain
    --iosMain
    --commonMain
--ios
When I added several iOS dependencies, it builds successfully and I can access the classes, but when I try to add
pod("CouchbaseLite-Enterprise")
I get the a similar error like
Exception in thread "main" java.lang.Error: /var/folders/4g/3s9scp9d5593dphx7n_7nhk40000gn/T/tmp1272859169392324213.m:1:9: fatal error: module 'CouchbaseLite-Enterpris not found
even though
CouchbaseLite-Enterprise
is an Obj-C library. Been sadly stuck on this for days
j
It seems the issue with the CouchbaseLite-Enterprise pod may have to do with the dash in the name. I create a YouTrack for this. But you're having a similar problem with the AFNetworking pod, which is odd as this pod does work for us.
m
@Jeff Lockhart, could you maybe share a simple project based from the template that's configured to use AFNetworking? That would help me narrow down if the issue is related to my project config or the installed software.
I've finally resolved this error. Just in case it helps someone in the future: apparently I didn't have
cocoapods-generate
installed (even though I was sure I did – famous last words).
👍 2
c
@Marcus I think I have that installed, can you try to see if you can add this dependency
pod(CouchbaseLite-Enterprise)
if it works? I'm also having a similar error but not with
AFNetworking
j
@Marcus didn't get a chance to put together a sample project, but glad to hear you figured it out.
m
@chi Doesn't work for me, I get
CocoaPods could not find compatible versions for pod
during Gradle sync. In a normal Xcode project, I can include it just fine. Did you have the same issue?
c
Thanks for the test @Marcus. I'm getting this error
Copy code
/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)
	...
m
@chi No idea about that. If you check that file at the specified line, what does it say there? (Not sure if you can access it after the fact, since it seems to be a temp file)
c
Ok, cool. I'll take a look, thanks
m
@chi After increasing the deployment target in my
cocoapods()
section, I now also get the same issue that you are getting. There's no temp file at the location specified.
c
Yeah, I agree. I think there's a bug with dependencies that have
-
because almost all dependency named as such doesn't work. There was a commit that tried to resolve this but I don't think it did. This is a serious issue I hope the Kotlin native team looks into
m
@chi I just had a look at their podspec and they specify another name for their
vendored_frameworks
. So if I try
Copy code
pod("CouchbaseLite-Enterprise", moduleName = "CouchbaseLite")
it seems to proceed further with the compilation (but is hit with
Exception in thread "main" java.lang.IllegalArgumentException: 'CBLQueryMeta' is going to be declared twice
). Maybe you can go somewhere from there?
c
That's interesting, I've been getting that error only if I use their
CouchbaseLite
library, which is a different library from the enterprise, maybe this is just compiling that module which I assume is a dependency for
CouchbaseLite-Enterprisee
I think its what happens because if I change the moduleName to something else it returns the original error
j
Interesting, so it seems the cocoapods plugin seems to be conflating the pod name and the module name, which doesn't allow for them to be different.
I tested and confirmed that
pod("CouchbaseLite-Enterprise", moduleName = "CouchbaseLite")
does work to add the enterprise version of CouchbaseLite after applying this workaround for the
CBLQueryMeta
error. Thanks for your help identifying this @Marcus. Do you understand what
moduleName
is doing under the hood that makes this work?
m
I have no deeper insights, but they way I understand it, you give moduleName the same value you would use to
import
the module in a native project when for whatever reason this is different from the name of the pod.
j
That's helpful insight, thanks. Most of the KMM APIs lack detailed documentation.