Kotlin Multiplatform Mobile combines cross-platform and native development

Kotlin Multiplatform Mobile
Today there are many approaches such as Xamarin, Flutter or React Native to develop cross-platform apps. To what extent does the Kotlin Multiplatform Mobile (KMM) differ from other frameworks?

Most of these approaches use a virtual environment in which the application runs. As a result, the design, behavior or connection of native libraries of the app often do not correspond to a natively implemented app, but rather represent a compromise between the different platforms.

KMM takes a different approach and focuses on separating the business logic from the rest of the app and only sharing that logic between platforms.

The architecture is specified by two layers. On the one hand, the business logic contains any logic that is the same between the platforms and represents the data model of the app. On the other, a view layer is defined, which contains the basic structure and the views of the app. This is platform-dependent and is therefore implemented differently for each platform, which means that a native “look and feel” can be achieved. You can access the business logic from this layer and use the common code. As UI and business logic are automatically separated by KMM, this enables a cleaner architecture.

Even if the business logic should form an encapsulated unit in order to separate it cleanly from dependencies and the UI, it can access iOS and Android-specific APIs through the expect / actual pattern and thus interact seamlessly with platform-specific code. For example, Play Services or CameraX can be connected to Android and, in return, CloudKit or AVFoundation to iOS.

Together with KMM there are already some libraries that address general problems such as HTTP requests by Ktor, SQLite databases by SQLDelight, so that these can be used directly in the business logic.

If a native Android app already exists, KMM can also be incorporated into it. To do this, the code that is to be used cross-platform must be encapsulated and can then be moved from a normal module to a common Kotlin module and used under iOS. This process can be scaled as required, as no code has to be migrated. It is therefore suitable for further developments without changing the existing code.

Since the shared code between the platforms is written in Kotlin, it can be written by Android developers without requiring a paradigm shift. This also eliminates additional training for the developer. Likewise, there is no need to introduce a new language into the code base, but Kotlin can continue to be used as a language. Due to its high similarity to Swift, iOS developers probably can use it.

Compared to other cross-platform solutions, Kotlin Multiplatform Mobile offers the advantage that only the logic layer of the app is made available independently of the platform. The rest of the app can thus be neatly connected to the platform. The disadvantages of cross-platform solutions, such as slow updates or incompatibility with existing code, are also eliminated, as KMM also provides appropriate support. In KMM, multithreading is solved via coroutines, which is currently not supported by Swift. There are also solutions for this that can circumvent this problem. Overall, it is a good way to create a cross-platform solution without destroying the native user experience of the app.

Jan Phillip Kretzschmar, Android developer at ZWEIDENKER


Want to know which development approach is suitable for your project? Contact us! We are happy to hear from you: anfrage@zweidenker.de

Artikel teilen

Tags: Cross-platform, Flutter, Kotlin, mobile Apps
Menu