https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

Sterling Albury

07/29/2020, 2:07 AM
Hello everyone. I’ve searched through the threads here and I know I’m not the first person to ask this, but I’m still struggling so I’m hoping to get some help. I’m currently trying to combine two shared kotlin mpp modules that use the cocoapods plugin into one framework. I just got the cocoapods sample working in the
JetBrains/kotlin-native
project using the
kotlin-native-xcode-11-4-workaround
library. I modified the
kotlin-library
project to have two modules, both of which are using the cocoapods plugin. I saw this thread where @Kris Wong found a project that uses a third module to aggregate things using the
packForXCode
task pattern, and I’ve tried to do basically the same thing but haven’t been successful getting that to work. I’ve also played with creating a fatFramework in a third module but I’m not sure I’m doing it correctly. I feel like from everything that I’ve read, this might be the best way to go. Has anyone aggregated two or more modules with cocoapods frameworks for ios targets? Would having a module that creates a fatFramework from other modules be a way to go? Should I be using the
export
function to export the module and the module dependecies in my ‘aggregate’ module, and then create the fatFramework? The project I’d like get to eventually would have a bunch of shared modules, some using cocoapod frameworks, some not, so I’m trying to find a good way to keep expanding on this. Thanks.
k

kpgalligan

07/29/2020, 12:08 PM
I’m going to share this internally. We’ve been doing experiments with combined modules. We have a fork of the Cocoapods plug-in, which has allowed us to do some funky things. Currently we are evaluating if we can get rid of the fork in 1.4, but we’ve needed it for 1.3
👍 1
k

Kevin S

07/29/2020, 4:04 PM
To Go off of what Kevin said, we are able to do this using a fork of the Cocapods plug-in. Our forked version is using
export
in the plug-in to allow us to have an aggregate, or top level, module that exports the submodules. So you’re on the right track with your
export
idea, and while it’s not available in the base cocoapods plug-in I believe you can use it with
packForXcode
. You have to first reference the submodule with an
api
call. i.e.
api(project(":submodule"))
and then export the module I also have a sample of how the export cocoapods process works here https://github.com/KevinSchildhorn/MultiKMPModulesSample Also worth noting that the aggregate, or top level, module is the best approach at the moment, as there’s some issues with including multiple kmp frameworks right now. Here’s some info on that. https://dev.to/touchlab/multiple-kotlin-frameworks-in-an-application-34e9
👍 2
Also worth noting that a fatFramework only means that it’s built for all the different iOS architectures, so it wouldn’t solve any issues with combining modules. That being said you could create a fat framework, from the aggregate module, if you need help creating one there’s an example in the kotlin docs under
building universal frameworks
https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#building-final-native-binaries
s

Sterling Albury

07/29/2020, 6:06 PM
Awesome, thank you both! I’ll definitely check out the cocoapods plugin fork.
👍 2
Can I still add something like
pod("AFNetworking", "~> 3.2.0")
in the cocoapodsext section? I'm currently getting a 'module ‘AFNetworking' not found' error. I noticed in Kevin S's sample project that there are no pods being imported, so I just wanted to double check that this is still possible to have. Now that I think about it that workaround lib might not work with the plugin fork. I'll clone the sample project and play with that (should have done that before posting)
k

kpgalligan

07/29/2020, 10:40 PM
I think with our fork, if you are making a dynamic framework, the
pod
statements don’t work. They only work with
isStatic = true
, or just leave
isStatic
off entirely. That’s one of the issues we have to resolve.
s

Sterling Albury

07/30/2020, 12:23 AM
Hm, removing the
iStatic
variable didn’t seem to help. I think
isStatic
needs to be false for dynamic frameworks. This
kotlin-native-xcode-11-4-workaround
library seems to act weird when there’s more than one module, so I think there’s something going on with the compatibility with the forked plugin. I’ll keep playing around to see if I can get something working.
Does touchlab have any plans to release a 1.4.0-rc version of the plugin by chance? I was pointed to this blog post you may have already seen about kotlin 1.4.0-rc and the updates with the native-cocoapods plugin that fixes some of the errors that are seen in 1.3.x plugin (that the workaround lib doesn’t address): https://blog.jetbrains.com/kotlin/2020/07/kotlin-1-4-rc-released/#kotlin-native
k

kpgalligan

07/30/2020, 11:48 PM
Being discussed
👌 1
2 Views