From Native to Multiplatform Development: Unpacking Kotlin and Compose

Dominik Dolny
No items found.

In short

This article unpacks Kotlin Multiplatform (KMP), Jetpack Compose, and Compose Multiplatform, explaining their roles, relationships, and how they stack up for React Native developers. It highlights KMP’s flexible logic-sharing, the native focus of Jetpack Compose, and the cross-platform potential of Compose Multiplatform.

Introduction

As a React Native developer, you're probably familiar with writing once and running everywhere. React Native lets you share both UI and business logic, creating apps for iOS and Android using a single JavaScript codebase.

But recently, you may have heard about Kotlin Multiplatform (KMP), Jetpack Compose, and Compose Multiplatform—and it’s not immediately obvious how they fit together. Are they like React Native? Do they replace native development entirely? How do these tools relate to each other?

Let’s explore these technologies from the perspective of a React Native developer, break down the confusion, and see how they compare to what we know.

What is Kotlin Multiplatform (KMP)?

Kotlin Multiplatform is a feature of Kotlin that enables developers to share business logic, data layers, and other non-UI code across multiple platforms, such as Android, iOS, Web, and Desktop. Unlike React Native, Kotlin Multiplatform doesn’t aim to replace native UI development entirely. It can be implemented in an existing application.

How Does It Work?

KMP lets you write platform-agnostic code in Kotlin and provides tools to integrate platform-specific code (e.g., Swift for iOS, Java/Kotlin for Android) where necessary.

Unique Approach - Unlike other cross-platform solutions that attempt to share everything, including UI, KMP focuses on sharing the core logic while allowing native UI on each platform.

What are typical use cases?

At any point in Android app development process, logic and classes can be separated into multiplatform module and used on other platforms. A common module can contain logic responsible for the REST communication, data storage, caching, data mapping/modification, and many more. KMP supports also JUnit and TestNG, so the code can be tested.

You’ve got a few different options to implement KMP.

how you can implement KMP

Sharing Individual Modules

You can share simple Kotlin Multiplatform (KMP) modules, such as those for analytics or networking, by writing them once in Kotlin and reusing them across all platforms.

This approach is ideal for large existing projects that are difficult to refactor. It allows for a gradual adoption of KMP, introducing it one module at a time and focusing only on areas that align with the project’s requirements.

Sharing the Data Layer

You can use Kotlin to write the entire data repository, integrating various data sources (e.g., web services, local settings, databases, GraphQL) with KMP libraries like Ktor HTTP Client, MultiPlatformSettings, SqlDelight, or Apollo GraphQL.

This approach suits existing projects where the data layer can be fully rewritten without excessive complexity or for new projects that prefer a cautious adoption of KMP. However, it requires maintaining platform-specific ViewModel and UI layers, which can become a significant maintenance challenge.

Sharing Both Data Layer and ViewModel

In addition to sharing the data layer, you can also share the ViewModel in KMP, defining all the data required by the UI layer.

This is the most compelling approach, as the platform-specific code is limited to the UI layer. It works especially well for new projects that use declarative UIs, such as Jetpack Compose (Android) and SwiftUI (iOS). With thin, stateless UI layers, this method enables sharing over 80% of the codebase using KMP.

What is Jetpack Compose?

Jetpack Compose is a modern, declarative UI framework developed by Google for building native Android UIs. It simplifies UI development by using a reactive, Kotlin-first approach. Think of Jetpack Compose as Android’s answer to React Native’s declarative UI approach—but built exclusively for native Android.

Compose focuses exclusively on creating UIs for native Android apps. It's a replacement for the traditional XML-based UI toolkit.

What is Compose Multiplatform?

Compose Multiplatform is an extension of Jetpack Compose developed by JetBrains to create declarative UIs across multiple platforms, such as Android, Desktop, and Web.

Relation to KMP

Compose Multiplatform can be used as the UI layer in a Kotlin Multiplatform project, but it is not part of Kotlin Multiplatform itself. Instead, it’s a toolkit that complements KMP by enabling shared UIs.

How are Jetpack Compose and Compose Multiplatform Different?

  1. Scope:
    • Jetpack Compose: Focused solely on Android.
    • Compose Multiplatform: Designed for multiple platforms, including Android, Desktop, and Web.
  2. Developers:
    • Jetpack Compose: Maintained by Google as part of the Android ecosystem.
    • Compose Multiplatform: Maintained by JetBrains to align with Kotlin’s multiplatform capabilities.
  3. Use Cases:
    • Jetpack Compose: For building Android-specific UIs.
    • Compose Multiplatform: For sharing UIs across platforms in Kotlin Multiplatform projects.
Many developers assume Jetpack Compose and Compose Multiplatform are the same because they share APIs and design patterns. While they are related, their scope and purposes differ significantly.

Also, it’s important to note that Kotlin Multiplatform itself is not tied to any specific UI framework. You can use native UIs or Compose Multiplatform depending on your project needs.

Conclusions

Kotlin Multiplatform, Jetpack Compose, and Compose Multiplatform are part of the evolving Kotlin ecosystem, but they solve different problems. Understanding these distinctions helps developers pick the right tools for their needs, whether building native Android apps, shared business logic, or fully shared multiplatform UIs.

For a React Native developer, Kotlin Multiplatform may feel like a paradigm shift because it doesn’t mandate sharing everything. Instead, it gives you the freedom to choose—share logic where it makes sense and build UIs natively or with tools like Compose Multiplatform

By embracing this flexibility, KMP allows you to balance shared code with the platform-specific experience users expect. If you’re exploring alternatives to React Native, Kotlin Multiplatform is worth a look at—not as a replacement but as a complementary option that excels in performance, flexibility, and native integration.

Latest update:
December 20, 2024

FAQ

No items found.
React Galaxy City
Get our newsletter

By subscribing to the newsletter, you give us consent to use your email address to deliver curated content. We will process your email address until you unsubscribe or otherwise object to the processing of your personal data for marketing purposes. You can unsubscribe or exercise other privacy rights at any time. For details, visit our Privacy Policy.

Callstack astronaut
Download our ebook

I agree to receive electronic communications By checking any of the boxes, you give us consent to use your email address for our direct marketing purposes, including the latest tech & biz updates. We will process your email address and names (if you have entered them into the above form) until you withdraw your consent to the processing of your names, or unsubscribe, or otherwise object to the processing of your personal data for marketing purposes. You can unsubscribe or exercise other privacy rights at any time. For details, visit our Privacy Policy.

By pressing the “Download” button, you give us consent to use your email address to send you a copy of the Ultimate Guide to React Native Optimization.