Kotlin Multiplatform — This is the way.

Jorge Luis Castro Medina
5 min readJul 23, 2023

--

Original image taken from Play Station

Hello everyone, as an Android developer and a Kotlin enthusiast, I would like to share a bit about Kotlin Multiplatform(KMP) and why I believe it is a very promising technology for developing cross-platform applications.

I have been motivated to expand my skills with tools that allow me to create applications for different environments, and that’s why I consider KMP to be a great alternative.

I have decided to create a series of articles about KMP primarily focused on mobile development, and this is the first one of them. Soon, I will be sharing more articles about this technology from the perspective of my experience.

Now, let’s get to the point!

What is Kotlin Multiplatform?

Kotlin Multiplatform technology streamlines the creation of cross-platform projects, streamlining the process of writing and maintaining code for various platforms. This approach offers the advantages of native programming while minimizing redundancy and saving development time.

Kotlin applications are compatible with various operating systems, encompassing iOS, Android, macOS, Windows, Linux, watchOS, and more.

It is just KMP!

In Droidcon Berlin 2023, Hadid Hariri begins by making a small clarification:

Kotlin Multiplatform Mobile (KMM)” was a mistake because it was misleading, and from now on we should only refer to “Kotlin Multiplatform (KMP)”

- Hadid Hariri-

Update on the Name of Kotlin Multiplatform

Different approaches to code sharing with Kotlin Multiplatform

With Kotlin Multiplatform, we have the flexibility to choose to what extent we want to share our code. Below, we can see how this framework provides us with different approaches, allowing us to decide whether to share only a small portion of our code or even share the entire code, including the UI, using Compose Multiplatform.

It is truly amazing what it allows us to do. 😊

Compose Multiplatform

https://www.jetbrains.com/lp/compose-multiplatform/

Why not Flutter, React Native, or maybe Xamarin?

With my response, I do not want to affirm that the other technologies are not good; on the contrary, they are very good and have their own niches. However, at this moment, besides Native Android, I will focus on KMP due to the great work being done by the teams at Google and JetBrains (Perhaps later on, I could learn another framework like Flutter, which I consider to be another good alternative). It is true that KMP is a less mature technology compared to others, but they are working hard to improve it.

I find KMP’s proposal very interesting, as it allows developers to choose the degree to which they want to share their code between different platforms. For example, today we could have shared business logic between Android and iOS applications while developing both with their native technologies, or we could have a single codebase using Compose Multiplatform — it’s incredible!

Another crucial point and a definite advantage over other technologies is that, being based on Kotlin, native Android developers could migrate their projects more easily and even reuse code from their existing native apps.

It is interesting to see how many companies have already adopted this technology in production, even though it is not in a stable version. As of the date of the article, Kotlin Multiplatform is in Beta version. You can see some use cases here.

How to learn Kotlin Multiplatform?

If you’re new to Kotlin Multiplatform, here are a few tips on how to get started:

  1. Learn the basics of Kotlin.
  2. Learn about Kotlin Multiplatform features.
  3. Create a Kotlin Multiplatform project.
  4. Start developing cross-platform applications with Kotlin.

In my opinion, having the basics of Kotlin, the easiest option is to use a pre-configured template to start, here are two of the JetBrains repositories:

Templates

make sure to read the Readme of each template well and have installed the necessary tools to continue 🙂.

If you want to have the same code for the user interface, you should use Compose Multiplatform. Compose for Desktop is already stable, but remember that it’s in alpha for iOS.

We can find libraries for most use cases from the standard libraries developed by JetBrains to libraries created by the community.

The idea is to have a stable ecosystem soon.

Look at this example of Abdul Basit

https://github.com/SEAbdulbasit/recipe-app

“Kotlin Multiplatform is here to stay” 👏🏻 🎉 🎊

If you like my content and want to support my work, you can give me a cup of coffee ☕️ 🥰

Follow me in

--

--

Jorge Luis Castro Medina

I'm a Software Engineer passionate about mobile technologies, and I like everything related to software design and architecture