How to stay modular on iOS using kmp + 3 repositor...
# multiplatform
a
How to stay modular on iOS using kmp + 3 repository architecture (ios/android/kmp)? I’m currently using an umbrella module approach for my KMP project: I expose an
:umbrella
module to iOS via a binary
.xcframework
, which internally depends on several modules like
:data
,
:core
,
:featureA
,
:featureB,
etc. Problem is: on iOS all code from every dependency is bundled in the final binary. That means I can’t optimize build size per target, and every consumer ends up with the full transitive dependency tree. The goal here is to be able to build specific ios targets using only :featureA and not :featureB for example. Has anyone faced this limitation? Is the only solution being to move to a monorepo architecture? Would love any tips, documentation or feedback on this 🙏
p
- Create one framework per target. - Have a specific gradle configurations where you include only certain modules in the umbrella, not all. -It will produce different umbrella frameworks, so the name will be dinamyc as well. Basically having multiple flavors of the umbrella
a
Thank you very much for you answer. I’m amazed how kmp architecture can be tricky. My company and I are studying the opportunity to move forward with KMP. But we have a lot of target on iOS, like 20 different ones, because we have modules like “regulation” which differ on each country. Is going mono-repo is the only suitable way to do kmp in this context? I cannot imagine creating 20 frameworks, which means maintain all of them each time a core dependency is modified…
p
I would say yes, monorepo but with multiple modules. Module implementations can live in separate repos if you want to but API modules have to be in the monorepo.
Basically you could separate all your 20+ modules in API + RealImplementation + EmptyImplementation. Then the targets that need a specific module, you include API + RealImplementation, those who don't need it API + EmptyImplementation
l
Related question: Let's say you have an iOS app with a widget extension. You create frameworks from
:app
and
:widget
modules for each of them. Both modules depend on a
:feature1
module. I haven't tested it yet, but I believe in this case, the
:feature1
code will be included twice in the final
.ipa
, in both the app and the widget frameworks. Has anyone dealt with this before and so can explain what happens?
a
Yes and you’ll get an error trying to use feature1 objects. Here a well explained article: https://medium.com/@maruchin/kmm-architecture-4-umbrella-a26a370071d5
l
I haven't read it yet, but if you use api and export you should be able to.
p
Right, you should only have one umbrella KMP entry point
a
if you have only one framework yes, but I as understood, if you create two frameworks which depend on the same feature1 module, you’ll run into errors
☝️ 1
p
Some people have included more than 1 framework but then you have to be really careful with this stuff. In this case you easily spotted because you own
:feature1
but if it is a transitive dependency you won't notice it so easy. That's why one entry point is the recommended way, so Gradle guarantees no duplicates dependencies are put together
l
@Anthony Mamode okay I see, the article says that the same feature1 objects will be considered different across both frameworks. Which is fine if you have separate
app
and
widget extension
targets that both consume only one of the frameworks at a time.
👍 1