What is Kotlin Multiplatform?

Kotlin Multiplatform is optional, natively-integrated, open-source, code sharing platform, based on the popular, modern language, Kotlin. Kotlin Multiplatform facilitates non-ui logic availability on many platforms.

Kotlin Multiplatform is really about pragmatic programming to help meet the growing demand to develop mobile applications on multiple platforms – a clean, clear way to avoid having to write the code twice.

What’s included in this introduction to Kotlin Multiplatform?

The ultimate guide in plain English to understand Kotlin Multiplatform (KMP):

  • In-depth explanations of why we define Kotlin Multiplatform as: optional, natively-integrated, open-source, code sharing platform, based on the popular, modern language, Kotlin. Kotlin Multiplatform facilitates non-ui logic availability on many platforms. 
  • Technical explanations of Kotlin Multiplatform
  • Our introduction to Kotlin Multiplatform presentation from 2019 ØreDev Conference (video recording and slide presentation)
  • Useful links for getting started quickly and minimal risk with Kotlin Multiplatform

Let’s get started…here’s how we think about Kotlin Multiplatform: 

 

It’s madness, really. An app is written for the web. Then for Android. Oh, and then it needs to be written for iOS, too. (At the same time.) Same app, different code. The question is, “Why?”

Development teams are essentially tripling their coding and testing efforts to ensure multiplatform coverage. It’s costly. It’s time-consuming.

And – this might be the craziest part – it’s uncertain what the shelf-life of the code will be. As we know, the future is unwritten.

As always, the goal is to be able to implement products more efficiently, and with better testing across platforms. And up to now, every multiplatform coding solution that has come along really hasn’t worked that well.

Kotlin Multiplatform is really about pragmatic programming to help meet the growing demand to develop mobile applications on multiple platforms – a clean, clear way to avoid having to write the code twice.

    Let’s start to expand on our definition of Kotlin Multiplatform, but first remember that “cross-platform” isn’t just one thing

    It is important to discuss the differences in “cross platform” tools. Obviously they all have different plusses and minuses, but we regularly get into discussions where suddenly “cross platform” is a singular thing. It’s not. 

    Optional sharing. Low risk. No big decisions.

    Start with a little shared. Feature by feature. Do a test in one sprint. You don’t need to commit to a (capital B) Big Decision. Risk is often under estimated with the developers we talk to, but is a big thing for management. It’s why Flutter is going to have a really hard time getting serious traction.

    Natively integrated. Smooth interop.

    Kotlin is designed to interop with the underlying platform. No 3rd environment. No VM. No “bridge”. That is a huge, fundamental difference.

    Kotlin Multiplatform Jet Brains

    Open source

    Pretty self explanatory, but we’re watching an entire ecosystem emerge over time, and Jetbrains and Google have created the Kotlin Foundation to help ensure open and independent development.

    Code sharing, not cross-platform

    Allows sharing of logic, optionally. It is not trying to be a single application unit able to run on all platforms.

    Advantages of Kotlin Multiplatform

    Popular

    It is important to note that Kotlin is popular, which means an existing, large community, and intense excitement about the language and the future. More support, libraries, hiring, training opportunity, etc.

    Modern

    The language itself is “modern”, but more than just the syntax. They are making arguably tough but forward thinking decisions WRT language and runtime design. Watch the Kotlinconf 2018 Keynote to hear about Saner Concurrency. They’re not simply bringing status quo to a new language. Also, it’s not “done”. Kotlin is evolving rapidly as time goes on.

    Not UI – well, not necessarily UI

    People will definitely try to build shared UI frameworks for Kotlin. They are now. I’ve seen demos.

    Shared UI is a history of pain and failure.

    Shared logic is the history of computers.

    – Kevin Galligan

    Kotlin Multiplatform Diagram

    Many platforms

    For native especially.

    IDE and tooling – JetBrains make it

    “I started using Kotlin in Android apps in mid-2014. Back then I assumed it would be popular because JetBrains made the language and IDE. Even back in 2008 for the ADC, I would edit my code in Intellij, then tab to Eclipse to build. JetBrains makes the good stuff.” – Kevin Galligan

    Why Kotlin Multiplatform?

    So why should you consider Kotlin Multiplatform for your next mobile development project?

    Here are a few high level bullet points that highlight why Kotlin Multiplatform is the future of multiplatform software development

    • High efficiency 
    • Low risk 
    • Modern language and tools
    • Highly engaged community

    More than just native mobile

    KMP is far more than just native mobile, but that’s where most of our experience is, and we think that’s where it’ll have a lot of the early traction. The “killer app” as it were.

    Mobile is easy

    They’re basically the same under the label. Threads, sql, files, networking, etc. They extremely similar. Sharing logic and architecture will be very doable with Kotlin Multiplatform. 

    Technically, though – what is Kotlin Multiplatform?

     

    Multiplatform is a compile-time construct. It is a way to represent “shared” code but have it be able to compile down and deploy to multiple platforms. JVM, JS, and Native are the broad targets.

    There are many specific permutations that you can compile to.

    In Java-land, you can target the raw JRE, or Android-specific. 

    JS can output code meant for browser or server. 

    Native has a whole bunch of targets. iOS (phone, watch, tv), MacOS, Linux, Windows, Android native, WebAssembly. 

    Conceptually speaking, these are the broad categories.

    Also, we’re largely focused on native mobile, so our examples and much of our library work lives here.

    Android and iOS on Kotlin Multiplatform

    How does Kotlin Multiplatform work?

    On iOS, the Kotlin Native compiler “merges” the common code and other source sets in that target’s hierarchy. 

    There can be multiple layers of specific sourcesets, but often with apps it’s just one for common and one for iOS.

    That compiles down and, assuming you’re building an app, you create a framework that Xcode can consume.

    Similarly, the Android side does some similar things. Although the pipeline can be a bit more direct. Kotlin has had more time to get friendly with Android.

    “This is also a good time to reinforce the idea that sharing is “optional”. Your actual apps aren’t all-or-nothing moving to shared Kotlin. One of the most important features is the native integration, and the ability to incrementally start sharing logic in existing apps.”

    Introduction to Kotlin Multiplatfrom presentation By Kevin Galligan (Øredev Conference, 2019)

    We designed a Kotlin Multiplatform starter project that gets you running on Android & iOS quickly. Register and receive KaMP Kit today!

    Final Thoughts

    Kotlin Multiplatform is a true multiplatform language 

    Kotlin Multiplatform enables you to write once, and test once. No siloed development teams. The same code can be used across Android, iOS and Web apps with no changes, eliminating the need for a translation layer. In essence, you’re reducing the amount of business logic coded by frontend developers by consolidating it efficiently with native code, but not oversimplifying abstractions.

    What’s not to love about that?

    No wonder there’s a groundswell of enthusiastic support in developer communities around the world. There are 1.5 million developers currently using Kotlin, with 96,000 GitHub repositories containing 100 million lines of code. And the numbers keep growing. It’s one of the top two languages that developers are hungry to learn.

    Kotlin Multiplatform was developed as a completely new language eight years ago, built from the ground up as a pragmatic approach to coding – a way to develop cleanly, clearly, and quickly.

    Simply put, Kotlin Multiplatform is more readable, reusable, interoperable, and safer, offering a first-rate developer experience.

    Kotlin Multiplatform for your complete tech stack 

    It’s a low-risk way to code because it dovetails seamlessly with the native platforms on Java, iOS, and the web. It’s a modern language that enables you to build on what you’ve already coded, without re-working or re-inventing what you already have. Plus, because the code you share is optional, you can start small and increment as desired.

    Kotlin Multiplatform is really an extension of Java, so it’s not a big leap for Java developers to start using Kotlin at all. In other words, you don’t have to make a big, potentially expensive decision to get started.

     

    In fact, on Android, Kotlin was built for direct JVM interoperability. On iOS, Kotlin is ready for prime time, and the first half of 2020 will see rapid mainstream adoption. And Google officially recommends Kotlin as a language of choice.

    The big considerations for any development team are cost, time, resources, and risk. And the big problem with the siloed approach is that organizations are often tripling them.

    At the same time, the wrong teams are working on the wrong projects. Back-end developers should focus on architecture as well as APIs – but not UI. Enabling your back-end developers to code and test the client and server features as a unified whole enables more rapid development with safer, higher quality and identical implementation.

    And that, my friends, is all there is about Kotlin Multiplatform. If you ever find someone feeling left behind and wondering, “What is Kotlin Multiplatform?” you know where you can point them too.

    So you have this handy ultimate guide to Kotlin Multiplatform, bookmark the link.

    Can you think of someone right now who should read this? Feel free to share this introduction to Kotlin Multiplatform.

    Our experience with Kotlin Multiplatform so far?

    No siloed teams.

    More streamlined workflows.

    Real multplatform functionality.

    Useful introduction to Kotlin Multiplatform resources 

    Kotlin Multiplatform Colab with Square
    Kotlin Multiplatform for mobile teams

    KMP FAQs with our thought leadership team; Justin, Sam & Kevin

     

    Q: Can I hire for KMP?

    Justin’s Answer

    “The community is growing quickly but this is new technology. At this point, there are very few experts, some devs with experience, and many more getting to know it. The greatest thing WRT hiring for KMP is that Kotlin is an easy language to hire for, and since it integrates well with new tech like Jetpack Compose and SwiftUI, even the people who built their
    careers on Android or iOS welcome it.”

    Kevin’s Answer

    “In general, hiring for positions that are seen as forward-thinking and working with popular technology will be appealing to developers. KMP is new, so there isn’t a lot of experience out there. However, there are many developers experienced with Kotlin for Android, and a lot of developer community interest in KMP. Competing for talent will be easier if you embrace technologies that developers are excited about. KMP is certainly no exception. Today, you should expect some ramp-up time for people with experience writing Kotlin for Android. However, offering experienced Android developers the chance to focus on KMP will increase the pool of candidates interested.”

    Q: Can I use KMP for an existing app?

    Sam’s Answer

    “Yes, being able to optionally share even small parts of your application lets you plug KMP in where it makes the most sense for you.”

    Q: How much of my code are we going to be able to share with KMP?

    Sam’s Answer

    “One of the great things about KMP is that you have a lot of flexibility in how much code is shared. As a rule we don’t recommend trying to share your UI code. Creating high quality UI is generally best accomplished using the tools and environment of each platform. Everything else is fair game. In practice you will find that the code you share will be the most
    critical business logic and the layers your platform developers are sick of doing twice.”

    Q: Does KMP work with Android WearOS, Apple WatchKit, tvOS?

    Kevin’s Answer

    “Kotlin 1.3.60 will add support for WatchKit and TvOS. Anything on the Android side already uses Kotlin, so there are no compatibility issues (Kotlin is the preferred language for Android).

    Q: What’s the value-add over other technologies?

    Justin’s Answer

    “Kotlin is THE language for Android. KMP doesn’t significantly change the way you develop native Android apps. KMP interop is native so there is very little run-time overhead and less boiler-plate code while developing. KMP outputs a standard iOS framework so iOS devs are still in familiar territory. By its nature, it keeps up with platform-specific technologies that motivate and excite strong native developers and those looking to join the space (retention and hiring). It doesn’t create its own ecosystem so it’s not a ‘B’ big decision, easy to iterate and revert, very little up-front cost compared to others.”

    Kevin’s Answer

    “It’s optional, meaning you can do some, and no big decisions. Natively-integrated: the interop is platform native, which is unlike pretty much all other options. Open source. Code sharing, so you can write and test your critical logic and architecture, but don’t build a dissatisfying UI. The language is popular and modern. That is important for libraries, hiring,
    and productivity.”

    Do you need to know more?

    If you have any questions relating to Kotlin Multiplatform or this intro to KMP guide then get in touch today and we will be happy to answer.