Are there any examples of wrapping native librarie...
# ios
j
Are there any examples of wrapping native libraries with Kotlin? I wrote a wrapper around two parallel, but different, Android and iOS libraries. The iOS library relies on Cocoapods for importing the dependency. However, it doesn’t then export the cocoapod dependency (dynamic loading). When I try to depend on the Kotlin cocoapod podspec, Gradle complains about an implicit dependency. Any ideas about the best way to configure the build tools for this?
Screenshot 2023-06-22 at 1.29.55 PM.png,Screenshot 2023-06-22 at 1.30.38 PM.png,Screenshot 2023-06-22 at 1.31.13 PM.png,Screenshot 2023-06-22 at 1.32.02 PM.png
Screenshot 2023-06-22 at 2.31.09 PM.png
j
You can do
pod ("AppAuth", "~> 1.6.2", linkOnly = true)
in the consuming app's build.gradles.kts to avoid generating unnecessary ObjC interop again and just link to the native dependency binary. You need this link directive because Kotlin doesn't embed the native dependency binary in the Kotlin framework it builds. If you're using cocoapods in the iOS app, it can pick up the dependency from the generated podspec.
j
But there’s no way to have it automatically pick those up from the consuming module, without explicitly naming the dependency of the submodule?
j
Not that I've seen. I suppose there could be some sort of klib metadata that declared native dependencies, but there's no guarantee the consuming project is using cocoapods or a different dependency management system. It could be possible to embed the dependency binary in the klib for the consuming app to link to, but there's no built-in support for doing something like this currently. Check out the cklib library for an example of this.