Kotlin Multiplatform — all operating systems at once?

Tom Klecha
intive Developers
Published in
4 min readOct 27, 2022

As an investor or an app developer, you can consider maximizing user base as one of your priorities. You would not like to exclude users from using your product because they do not own a specific device. On top of that, rewriting the business logic code many times is a waste of resources. On the market, there are already a few frameworks offering cross-platform development.

The most popular and currently hyped solution is Flutter — a Google framework based on Dart programming language. It offers writing the application on the most popular platforms within one codebase. When creating a new project you tick the box on which platform you would like to develop and voilà!

You can start developing!

Creating a new app in Flutter

The downfall of this solution is learning a new programing language — Dart.

For me, as an Android Developer, writing IMO in the language of the best ketchup in the world it would a dream to use only one codebase to develop a cross-platform app

Kotlin — top league ketchup, as well as the programming language. Similarities are not on purpose

And then, here we are — Kotlin Multiplatform! This is what I was waiting for! One codebase and we can develop for all platforms at the same moment, right? Right?

Now, Kotlin has presented Kotlin Multiplatform Mobile (KMM). Isn’t multiplatform already suggesting that we can develop on all platforms at once? It is not that straightforward.

As we saw in the example above with Flutter, is it as simple as ticking the box to create a project for a given platform. Kotlin has a few different options.

Currently, in Beta, we have KMM, which gives us the possibility to develop a full app or a library. shared code between Android and iOS. Android Studio added this functionality as a plugin.

Explanation of new KMM app
Explanation of new KMM library

In the case of writing code for other platforms, you will need to use Intellij Idea. From there, things are getting more complicated. When creating a new project we see a few different project options.

Disclaimer — as of today, Kotlin Multiplatform is still in alpha. So those features are likely to be subject to change.

Creating new Kotlin Multiplatform project in Intellij

As presented in the image above we can see plenty of templates to create a new project:

  • Multiplatform
  • Kotlin/JS
  • Compose Multiplatform

Main concept of each template is to share common code across them. What are the differences? Let’s start from the bottom.

Compose Multiplatform as the name suggests, includes the compose framework. Unfortunately works only with Kotlin version 1.6 for now.

Kotlin/JS focuses on web applications with the addition of other frameworks like React or NodeJS.

The part we are most interested in — Multiplatform.
At the beginning Full-Stack Web App. The template contains a web frontend, written in Kotlin/JS. The backend side is in Kotlin/JVM. Next, the library template — writing common code to share across indicated platforms. Finally — A native application that generates an app module for platforms based on Kotlin/Native.

Adding new targets with Native Application template

There are some limitations towards adding certain targets, listed here. Instead, we can use some of the combinations suggested by Kotlin Docs:

  • Android and iOS application — mentioned before as a Kotlin Multiplatform Mobile
  • Full stack Web application — used for sharing the business logic on the client/server side
  • Multiplatform library — creating a multiplatform library
  • Common code for mobile and web applications — share business logic between Android/iOS and Web apps without UI side

Conclusion

So, Kotlin is currently not as user-friendly to develop for all platforms at once. Reminder, Kotlin Multiplatform is still in Alpha. Nonetheless, those possibilities are a silver lining for future concepts. For some, it might be enough to share code between mobile platforms. Till then, I encourage you to check Kotlin webinars dedicated to the topic of Kotlin Multiplatform Mobile!

Happy coding!

Documentation:

https://kotlinlang.org/docs/multiplatform.html

https://flutter.dev/multi-platform

--

--