Do I need an umbrella ☔️ (framework)?
- Pamela

- 16 hours ago
- 2 min read

“I am using Kotlin Multiplatform (KMP), do I need to use an umbrella framework?” The short answer is: “Yes, if you are targeting Apple and your project is a multi-module project.”

Let’s start by explaining what an umbrella framework is: it is a module you use to aggregate all your other modules into a single module for use in an iOS app. In the diagram, we can access the code in modules A, B, and C from our iOS app because we are importing the umbrella framework.
There are a couple of reasons for this:
De-duplication of stdlib
Smaller app sizes
Compatibility of code across modules
No duplication of stdlib
Whenever we export a module, this module needs to be bundled in a way that makes it independent. For this reason, the Kotlin/Native team decided to bundle the Kotlin stdlib with each exported module when making the binary. As you can imagine, there would be as many Kotlin stdlibs in an app as there are modules. An umbrella framework ensures that there is only one Kotlin stdlib in the iOS app - that of the umbrella module’s, thereby deduplicating this dependency.
Smaller app sizes
Following on from our previous point, using the umbrella framework leads to smaller app sizes because there are fewer or less duplicates of dependencies.
Compatibility of code across modules

The next reason is a little trickier to grasp, so let’s first look at an example. Say that in module A, we have a class A. This means that in the framework for module A, there is also a binary format for class A. In module B, we have a class B that depends on class A. So, we would expect in the framework for B, there to be a binary format for class B and a copy of class A. Similarly, for module C, you can see we would have a framework containing class C and a copy of class A for module C.
However, the original class A and the copies of class A in modules B and C are not compatible. If you tried to use them interchangeably, you would very soon get a type mismatch. For example, C(getB().a) does not compile.
Yet again, we need an umbrella framework to help us here. Now, there will only be one class A in the umbrella framework, and module A, B, and C can all refer to that class’s binary format. We can use code like C(getB().a) without worrying about type mismatches.
While one does not need an umbrella framework when using a multi-module setup on Android, this mindset is not helpful when working with KMP. Instead, if you are targeting Apple as a platform for your apps, make sure to use an umbrella framework.
.jpg)



Comments