DEV Community

Sebastien Lorber
Sebastien Lorber

Posted on • Updated on

Kotlin multiplatform: a new cross-platform contender to ReactNative and Flutter

After ReactNative and Flutter, a new cross-platform solution is emerging: Kotlin Multiplatform Mobile (KMM) has just been released in alpha.

Alt Text


Introduction

Kotlin Multiplatform allows you to share logic written in Kotlin between Android and iOS, and to access native APIs for each platform.

At the moment, it is not possible to share UI code, and we don't really know if this is an actual goal of this project.

But why not a cross-platform UI solution based on Jetpack Compose (alpha released last week), the Kotlin declarative UI framework built by Google?

It is currently possible to share code such as:

  • business logic
  • persistence
  • network
  • concurrency
  • ...

The Kotlin code becomes available for consuming in SwiftUI/Objective-C based iOS applications.

Kotlin multiplatform ecosystem

It's a whole ecosystem that is likely to be built on KMP, with the publication of cross-platform modules. For example, Reaktive is a Kotlin multiplatform module of Reactive Extensions (Observables).

Kotlin is already running on the backend with Ktor, and on the frontend with Kotlin / JS.

An open-sourced demo app (PeopleInSpace) supports all these platforms:

  • Android (Jetpack Compose)
  • iOS, watchOS, macOS (SwiftUI)
  • Web (ReactJS)
  • backend (JVM/Ktor)

It looks like, if sharing UI code is not needed, Kotlin is able to share everything else, and would be a good cross-platform choice.


Alternatives

I'm totally biased toward ReactNative, as I'm running it on my Gatsby static blog, and will give a talk about cross-platform at ReactNative Europe at the end of the week :)

React-Native is a strong platform for cross-platform development. It has many escape hatches which makes it not so risky to adopt. I almost see it as a dependency injection framework to inject platform-specific primitives where default React-Native abstractions are not a good fit. The React-Native re-architecture (Fabric/JSI/Turbomodules) should be available in the upcoming year, and help remove many of the performance issues we could encounter so far. It is also a serious cross-platform solution, with Microsoft building React-Native-MacOs and React-Native-Windows, and Web support already used on highly critical products such as Twitter (see React-Native-Web and my blog post about Atomic CSS-in-JS).

Flutter is also a strong platform. Its tradeoffs are different compared React-Native, but both platforms looks good, and should be chosen according to the usecase and context. The mobile support is good and can very often outperform ReactNative, but web support is improving but it's still not perfect, as SEO and small JS bundles matter for the web.

SwiftUI: I'm not sure Apple wants to help on cross-platform development. But there is this project Scade that enables to create Android apps with Swift, Vapor that allows to run Swift on the backend, and Gryphon to transform Swift code to Kotlin. It does not look like the most mature ecosystem, not receiving any big player investments, but that could change. Edit: just found out about Tokamak.

WebView: Adobe is stopping to invest in PhoneGap, yet Max Lynch, creator of Ionic and Capacitor (modern alternative to Cordova), continue to bet on the web platform, and think ReactJS (and not ReactNative) might be the better choice for cross-platform


Conclusion

This is exciting times for cross-platform development, and happy to see a new viable alternatives to more established ones.

If you like cross-platform related news, follow me on Twitter.

Top comments (2)

Collapse
 
jillesvangurp profile image
Jilles van Gurp

You missed one obvious thing: react native can be done using kotlin-js. There are not a lot of people doing that and the tooling is probably a little rough on the edges but it's pretty much the only way to do native(ish) UI on IOS & Android using Kotlin right now.

Collapse
 
sebastienlorber profile image
Sebastien Lorber • Edited

Yeah but that wouldn't be exactly the same to me. People are already using Scala, Vue or whatever to build ReactNative apps. At some point you have to keep the tech stack understandable, and avoid stacking too many layers on top of each others. If I were to adopt Kotlin for cross-platform, it's clearly not because Kotlin is a better language over JS / TypeScript / ReasonML / ScalaJS, but I'd expect to give me something else that I don't have currently.

I don't want to use Kotlin to transpile to JS to build ReactNative apps in the end, as I'm already fine using TS or ReasonML, and wouldn't want to be on my own in the niche Kotlin to JS ecosystem. Every lang target JS nowadays, so I don't feel Kotlin/JS will ever be mainstream anyway, it's just for folks that really want hard to keep using Kotlin everywhere