Will Kotlin Multiplatform Mobile change the way we make mobile applications? [1/n]

Debanshu Datta
Backyard Programmers
5 min readNov 20, 2022

If you are a mobile developer and not living under a rock, you should have heard about Kotlin Multiplatform and how it revolutionizes the mobile development industry.

Let me first explain it to you Kotlin Multiplatform Mobile (KMM) is an SDK designed to simplify the development of cross-platform mobile applications. You can share common code between iOS and Android apps and write platform-specific code only where it’s necessary. Common use cases for Kotlin Multiplatform Mobile include implementing a native UI or working with platform-specific APIs.

What is Kotlin Multiplatform Mobile (KMM)?

Kotlin Multiplatform Mobile is an SDK for iOS and Android app development. It offers all the combined benefits of creating cross-platform and native apps. Maintain a single codebase for networking, data storage, analytics, and the other logic of your Android and iOS apps. Implement native UIs and leverage other features specific to Android and iOS devices.

It is trusted in production by many of the world’s leading companies, including Philips, Netflix, Leroy Merlin, and VMWare.

Problems that KMM is trying to solve?

  • Time and efforts saved by sharing code — In mobile development, it is always an issue that the same code has to be written in both android and iOS with KMM it is really easy that the business logic can easily be shared between in turn will rescue the time taken to rewrite the same business logic.
  • Native Performance — With cross-platform solutions performance has always been an issue. Since the introduction of KMM separated out only the business logic, the UI remains the same native, with easier access to hardware like Camara, etc. Unlike cross-platform options like Flutter, Ionic, etc.
  • Connect to platform-specific APIs without overhead — KMM is not overlapped with your native device usage. If you want to access your device camera you natively access it with native Swift code for iOS and Kotlin for Android. This approach is very much better than the approach that Flutter or React Native takes.

How is KMM solving problems?

Share code on platforms

If you have common business logic for all platforms, you don’t need to write the same code for each platform — share it in the common source set.

One language for cross-platform and native apps

There’s no need to introduce any new programming languages to your codebase to make your app cross-platform. Make your existing Android app work on iOS devices without changing much of your existing code.

Kotlin syntax follows the same concepts used for iOS development and is easy for iOS developers to learn.

Connect to platform-specific APIs

If you’re developing a multiplatform application that needs to access platform-specific APIs that implement the required functionality (for example, generating a UUID), use the Kotlin mechanism of expected and actual declarations.

With this mechanism, a common source set defines an expected declaration, and platform source sets must provide the actual declaration that corresponds to the expected declaration. This works for most Kotlin declarations, such as functions, classes, interfaces, enumerations, properties, and annotations.

The compiler ensures that every declaration marked with the expect keyword in the common module has the corresponding declarations marked with the actual keyword in all platform modules. The IDE provides tools that help you create the missing actual declarations.

Familiar with tooling and ecosystem

Multiplatform Mobile leverages the multiplatform capabilities of Kotlin and provides tooling for cross-platform mobile development in Android Studio. The multiplatform library ecosystem is growing. A number of big libraries such as Ktor, SQLDelight, Apollo, and Koin have already adopted Kotlin Multiplatform.

How Kotlin Multiplatform works

  • Common Kotlin includes the language, core libraries, and basic tools. Code written in common Kotlin works everywhere on all platforms.
  • With Kotlin Multiplatform libraries, you can reuse the multiplatform logic in common and platform-specific code. Common code can rely on libraries that cover tasks such as HTTP, serialization, and managing coroutines.
  • To interop with platforms, use platform-specific versions of Kotlin. Platform-specific versions of Kotlin (Kotlin/JVM, Kotlin/JS, Kotlin/Native) include extensions to the Kotlin language, and platform-specific libraries and tools.
  • Through these platforms, you can access the platform's native code (JVM, JS, and Native) and leverage all native capabilities.

These are all the reasons why I feel Kotlin Multiplatform will change the way we think of approaches to building a mobile application. It provides the best of both worlds by providing the power to share business logic between platforms with the speed of native approaches.

For any doubts and suggestions, you can reach out on my Instagram, or LinkedIn. Follow me for Kotlin content and more. Happy Coding!

I will well appreciate one of these 👏

Recent Post

--

--

Debanshu Datta
Backyard Programmers

Android(L2) @Gojek | Mobile Developer | Backend Developer (Java/Kotlin)