Hello :wave: I am trying to use a cocoapod in our multi module KM Project. I have all bindings showi...
d
Hello 👋 I am trying to use a cocoapod in our multi module KM Project. I have all bindings showing up, but am two experiencing two seperate issues during compile time. 1. It seems as though the
assemble<ProjectName>RelaseXCFramework
does not automatically link the cocoapod frameworks into the build. for each architecture i have to manually specify the libraries cocoapod location using
Copy code
linkerOpts("-F$frameworkPath")
                        linkerOpts("-rpath", frameworkPath)
                        linkerOpts("-framework", "<Library>"
Once i do this, i can get a successful build, but a failure once i utilize the framework in my project with the following errror
Copy code
dyld[32068]: Library not loaded: <FrameworkClass>
I feel like I have an incorrect setting as no where in docs is it stated that i have to manually link cocoapod frameworks. Any suggestions?
l
Can you share what the Cocoapod is? Keep in mind that if it is a Swift Cocoapod, you can only call into objc annotated methods and classes.
Also, check <module>/build/cocoapods/defs/<podName>.def, which should be created during the build process. This is the generated def file.
d
It's launch darkly.
I'll get a link in a few. Afk atm
l
https://github.com/CocoaPods/Specs/blob/master/Specs/f/0/6/LaunchDarkly/8.0.0/LaunchDarkly.podspec.json I’m at work right now, so I’ve only glanced at it, but it looks like there is Objective-C support. Are you using the cocoapods Kotlin plugin and adding it to the cocoapods block?
d
Yup. I'll get ya a snippet.
The IDE picks up all the bindings
And I have it compiling too now
Copy code
kotlin {

    cocoapods {
        ios.deploymentTarget = "13.5"

        summary = "CocoaPods Library"
        homepage = "<https://github.com/JetBrains/kotlin>"

        pod("LaunchDarkly") {
            version = "~> 8.0"
        }
    }
}
l
You said you got it compiling now. Did you fix the issue?
d
nope, the xcframework compiles succesfully but when i open the iOS app with the framework I get
Copy code
dyld[32068]: Library not loaded: <FrameworkClass>
FrameworkClass
is actually like
LDClient
which is a launch darkly class
l
Go into XCode and check the build phases tab.
Under ‘Link Binary with Libraries’, there’s a plus button. Click it and search for the framework it says is missing.
d
shouldn't the framework from launch darkly be baked into the framework that i created from my KM project?
or is that not how it works
l
Depends on if it’s static or dynamic. I think Apple’s wanting people to lean towards dynamic frameworks now.
d
i believe its dynamic
l
When you link a static framework, it builds it into your binary. When you link a dynamic framework, it just creates stubs (you can check by running ‘nm -C | grep <some method in the library>’ and checking the second column (I want to say ‘U’ means dynamically linked)). If you link against a dynamic library, it has to be present on the system when your app starts.
d
interesting, makes sense. Should i be able to just point my iOS app to use launch darkly through cocoapods?
l
You can tell XCode to bundle the binary in with your app.
I think you still have to tell XCode to include the binary. I think that’s what the ‘link binary with libraries’ section of ‘Build Phases’ is for. You have to do this for native iOS development too, I believe.
d
alright. well this gives a bunch to go on. I unfortunately had to switch branches to continue work on something else. But ill try out your suggestions today.
one other thing.
l
Looking at my project using cocoapods, there’s something at the end of ‘Build Phases’ called ‘[CP] Embed Pods Framework’ that calls a script. Looks like that script is what does it.
d
in order for me to get the framework compiled. I have to manually specify the framework for each architecture in the binaries setup using
Copy code
val armFramework = "${parent!!.rootDir.absolutePath}/integrations/integration-launch-darkly/build/cocoapods/synthetic/IOS/build/Release-iphoneos/LaunchDarkly"
                        val frameworkPath = x86Framework
                        linkerOpts("-F$frameworkPath")
                        linkerOpts("-rpath", frameworkPath)
                        linkerOpts("-framework", "LaunchDarkly")
your cocoapod project being your iOS app?
l
Yes. An app that uses cocoapods in it. Fixed the wording.
d
interesting, im worried about all the issues im going to go through getting this working on CI lol
without writing a similar script i suppose
l
I think the kotlin multiplatform plugin creates the script.
Here’s the script I see.
"${PODS_ROOT}/Target Support Files/Pods-app-ios/Pods-app-ios-frameworks.sh"
This requires me to run a syncFramework gradle task once before I can build via XCode (but only once until I clean the project).
d
ohh so i see this in the .podspec file generated right?
l
I think so. If I remember correctly, when you add the pod via XCode it sets this up.
d
and this is assuming who ever is consuming this library also has the KM project locally
l
They’ll have to add LaunchDarkly to their Podfile from what I remember. I don’t think KMM can tell a consumer of a library to set up cocoapods automatically yet.
d
alright, I wish this was a bit more documented some where. I appreciate all your help
l
Cocoapods in general are a bit iffy at times. It would be nice if JB were to add swift package support to the KMM plugin (even if only for Objective-C bindings).
d
all in good time i hope