# 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](https://blog.jetbrains.com/kotlin/2020/08/kotlin-multiplatform-mobile-goes-alpha/).

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/sd8f1fcs3x9nvyao3sxa.jpg)

---

# 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](https://developer.android.com/jetpack/compose)), 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](https://github.com/badoo/Reaktive) is a Kotlin multiplatform module of Reactive Extensions (Observables).


Kotlin is already running on the backend with [Ktor](https://ktor.io/), and on the frontend with [Kotlin / JS](https://kotlinlang.org/docs/tutorials/javascript/kotlin-to-javascript/kotlin-to-javascript.html).

An open-sourced demo app ([PeopleInSpace](https://github.com/joreilly/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](https://sebastienlorber.com/using-expo-in-gatsby), and will give a [talk about cross-platform at ReactNative Europe](https://www.react-native.eu/#speakers) 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](https://formidable.com/blog/2019/react-codegen-part-1/) (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](https://microsoft.github.io/react-native-windows/), and Web support already used on highly critical products such as Twitter (see [React-Native-Web](https://github.com/necolas/react-native-web) and my blog post about [Atomic CSS-in-JS](https://sebastienlorber.com/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](https://dev.to/solutelabs/flutter-for-web-an-ultimate-guide-2j76), 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](https://www.scade.io/) that enables to create Android apps with Swift, and [Vapor](https://vapor.codes/) allows to run Swift on the backend. It does not look like the most mature option.

**WebView**: Adobe is [stopping to invest in PhoneGap](https://blog.phonegap.com/update-for-customers-using-phonegap-and-phonegap-build-cc701c77502c), 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](https://dev.to/ionic/saying-goodbye-to-phonegap-1gp4)

---

# 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](https://twitter.com/sebastienlorber).
