Kotlin Multiplatform for Clean Architecture

Click for: original source

Jan Freymann wrote this piece about Kotlin and Kotlin Multiplatform, which enables us to write the same code for the JVM as well as LLVM!

Kotlin Multiplatform is getting more and more traction in the community right now. It is also heavily supported by JetBrains and Google, which probably means that this is more than yet another hyped cross-platform framework.

Following the write once, compile everywhere pattern, Kotlin multiplatform code is regular Kotlin code compiled to JVM bytecode for Android and to LLVM bytecode for iOS. The concept of compiling a shared library to native code for both mobile platforms is not new.

Primary goal is to build a minimal sample app which uses the MVVM pattern with the components persistence layer (i.e., database), repositories, view models and a HTTP-client to sync data. All components should be kept in the shared codebase, only the code for the UI should be platform-specific.

You can find the final code on GitHub. The tutorial then describes:

  • Scaffolding
  • Persistence
  • HTTP client
  • Repositories
  • View models
  • Tests

A major showstopper at the moment is the lack of support for co-routines on a background thread—JetBrains is working on it, though. Excellent tutorial!

[Read More]

Tags ios kotlin programming android app-development