What Is Kotlin Multiplatform
This issue persists further if they also want to be present in desktop and web apps. This is precisely the problem that Kotlin Multiplatform was designed to solve.
Furthermore, technology teams have to decide whether to develop (and iterate) their apps natively or through a cross-platform approach. While there are a number of technology options (e.g. React Native, Flutter) for developing applications across different platforms, devices, and operating systems, Kotlin Multiplatform (KMP) has the unique capability to accommodate both native and cross-platform development approaches even if the app has been built and already available to users.
What is Kotlin Multiplatform? This guide serves as a fundamental introduction to what Kotlin Multiplatform entails, encompassing its advantages and drawbacks. It provides a comprehensive overview of Kotlin Multiplatform, offering insights into its strengths and weaknesses for developers and stakeholders alike. We’ll also briefly go through the kind of apps KMP is most suitable for. This guide is especially helpful for those in companies, whether startups or enterprises, looking to implement digital products more easily and effectively across different types of platforms, particularly Android, iOS, and web apps.
Kotlin Multiplatform: An Introduction
Kotlin Multiplatform is a software development kit (SDK) that facilitates the development of cross-platform applications by providing developers with the capability to write shared business logic code that can be utilized across multiple platforms. This SDK simplifies the process of cross-platform app development by allowing developers to create a single codebase for the core functionality of their applications, reducing duplication of effort and enhancing code reusability.
By utilizing Kotlin Multiplatform, Android and iOS developers can reduce the amount of coding and testing efforts, as they only need to write and test their code once.
Kotlin Multiplatform Mobile (KMM), a subset of KMP, enables developers to code logic for iOS and Android from a single codebase. Kotlin Multiplatform also allows development on desktop, and web applications.
KMP was developed by Jetbrains using Kotlin language. It was released as part of Kotlin 1.2 in 2017 in an effort by JetBrains to speed up and simplify development in building apps across different types of devices. Currently, it is in the beta stage .
Based on a survey conducted by JetBrains in the second half of 2021, about 28% of mobile developers who participated said that they were already using Kotlin Multiplatform in their mobile app development projects.
While KMP can sometimes be alluded to as a framework, it’s really a set of technologies that allow developers to share code across platforms and combine the advantages of both cross-platform and native development approaches. For instance, when creating a mobile app available in both iOS and Android, the development team can share common code for both operating systems and write platform-specific code only where it's necessary.
Is Kotlin Multiplatform stable?
Initially, Kotlin Multiplatform Mobile was in an experimental phase where the Kotlin team explored different techniques for memory management, libraries, and project configuration, aiming to optimize the development process. However, the period of experimentation has concluded, and now it offers a stable and refined solution for cross-platform app development.
The invaluable feedback from early adopters of KMM, which includes renowned companies like Philips, Netflix, Baidu, and VMWare, played a pivotal role in JetBrains' quest to strike the perfect balance. Their insights helped JetBrains enable code reuse while offering access to platform-specific features. The company announced that Kotlin Multiplatform Mobile has advanced to the Beta stage and is steadily progressing towards stability.
The promotion of Kotlin Multiplatform Mobile to Beta signifies its advanced stage of development and assures its reliability for integration into your projects. Furthermore, JetBrains is actively committed to minimizing any migration challenges you may come across, demonstrating their dedication to ensuring a smooth transition.
What platforms does Kotlin Multiplatform support?
- One of the primary use cases of Kotlin Multiplatform is facilitating code sharing across mobile platforms. Kotlin Multiplatform for mobile empowers developers to create cross-platform mobile applications, enabling the sharing of code between Android and iOS. This shared codebase can encompass various essential functionalities such as networking, data storage, data validation, analytics, computations, and other application logic.
- Compose Multiplatform allows for the sharing of user interfaces (UIs) across multiple desktop platforms, including Windows, macOS, and Linux.
- It offers the capability to create multiplatform libraries that consist of shared code as well as platform-specific implementations for JVM, web, and native platforms. Once these multiplatform libraries are published, they can be utilized as dependencies in other cross-platform projects.
Benefits of Kotlin Multiplatform
In contrast to other multiplatform solutions, businesses gain a better chance of a successful project delivery with KMP, especially in minimizing technical mistakes and other technology risks. Here are the advantages of implementing your cross-platform digital products with Kotlin Multiplatform.
Optionality in code sharing
Compared to other cross-platform technologies, a key differentiating factor for Kotlin Multiplatform is its optionality in code sharing. Development teams can choose to have a shared codebase only for the parts, features, or modules they want to.
In addition, if an app is already available in one platform, developers don’t have to scrap the code they’ve already written. It’s possible to redevelop or enhance the existing app bit by bit, feature by feature, while simultaneously building the app in another platform. This can help businesses lower the risk of bugs and other types of errors when aligning the same app in different platforms.
Ability to expand and enhance native apps
Businesses can still deploy KMP even if their development teams have already built separate native apps (e.g. in both iOS and Android) that don't share common code. When iterating for future releases, developers can start using Kotlin Multiplatform at any point and share as much or as little of the code they choose to.
When introducing new features, the development team can consider sharing code between platforms without having to refactor everything they've done so far. In addition, Kotlin code is interoperable with the other languages, particularly Java, Swift, or Objective-C. All these make KMP a powerful tool that can work with and enhance native applications.
Reduction in development timelines and faster time-to-market
Based on experience, using Kotlin Multiplatform for a cross-platform app development project can save technology teams 30-50% of development time. For instance, Kotlin can save around 40% of lines of code when compared to Java. Furthermore, because Android and iOS apps use the same lines of code for business logic, adding and testing new features is easier and faster.
Enhanced collaboration between platform specialists
The shared codebase tends to promote better communication and coordination between platform specialists (e.g. Android and iOS developers). By design, Kotlin facilitates cooperation among developers through clarity of roles and division of tasks.
For example, while Android developers work on user inflow, the iOS team can work on post-create flow. The code produced by the iOS team can then be included in the next sprint by the Android team, or vice versa.
Better consistency between platforms
Further, having a shared codebase results in better consistency on the architecture and features. It also tends to help the team of developers spot more errors early in development of a cross-platform application.
Savings on development costs
Kotlin Multiplatform works well in cutting project costs because businesses don't have to construct separate teams for each platform or hire engineers to write the same lines of code twice (or even more). From experience and anecdotes from the KMP community, building an app on both iOS and Android comes out as cheaper than developing seperate native apps.
Growing community of developers
Engineering teams of many tech and non-tech businesses all over the world have already been increasing their capabilities in the Kotlin programming language, including KMP and KMM. This is partly due to Google's decision to adopt Kotlin as its preferred language for Android.
For example, part of why the cloud computing firm VMware started using KMM was because of the strong support by Jetbrains and Google. The talent pool and opportunities for KMP devs will continue to grow with such an enabling environment.
Disadvantages of Kotlin Multiplatform
No single set of tools can solve every bit of problem when building applications in different platforms. These are the drawbacks of Kotlin Multiplatform that you should be aware of.
Libraries still in early days
KMP offers robust libraries for key tasks, particularly local storage, networking, JSON parsing, concurrency, logging, and testing.Its libraries or packages aren’t as well tested compared to more established frameworks. Developers need to create wrappers around native solutions. To work on the shared layer, iOS developers just beginning with Kotlin will likely need help from Android developers.
However, projects using KMP have the ability to use platform-specific libraries such as platform-specific firebase wrappers. In addition, while online resources on KMP aren’t as many and rich compared to those for established tools, frameworks, and languages, this is expected to grow as the Kotlin ecosystem and community of developers expands.
Lack of support for sharing UI logic across platforms
As of now, Kotlin Multiplatform doesn’t support sharing UI logic across platforms. When writing UI code for iOS, developers have no option but to do the UI part natively so the design consistency isn't actually forced by using KMP. Instead, Apple’s frameworks such as SwiftUI or UIKit are used.
However, there’s a possibility of sharing UI code in the future with the help of Jetpack Compose and Compose for Desktop. Compose multi platform: share code for UI for desktops, web and Android (iOS isn't really viable atm). It would complement the KMM solution nicely, since it's also in Kotlin.
Limitations with Swift
There are still certain limits and unpredictable behaviors when translating Kotlin code to Objective-C (the language of iOS) when using KMP to build an iOS app. Default method parameters in Kotlin, for example, don't function after translation because Objective-C doesn't allow default parameters.
In addition, translation from Kotlin to Objective-C tends to be time-consuming, which often delays the iOS development phase. JetBrains has said that they're already working to fix these issues related to Swift and Objective-C.
What kind of apps is Kotlin Multiplatform most suitable for?
Despite still being in beta stage, Kotlin Multiplatform has already attracted industry leaders such as Netflix, PlanGrid, CashApp, Memrise, and VMware, among many other well-known companies and apps in using KMP.
As the technology is still relatively young, its community of developers is highly optimistic of what else it can offer for cross-platform development in the years to come. Whether your app is in eCommerce, fintech, education, media, health, or any other vertical or industry, Kotlin Multiplatform can be an invaluable addition to your tech stack. Based on KMP and KMM apps already out there, here are some key use cases wherein Kotlin Multiplatform stands out compared to its peers.
When your app is already in Android and you wish to expand to iOS
Instead of building another native app, wherein you’ll need to adapt or duplicate all of the code you've already written for Android, KMP makes the job easier. It’s precisely this situation that Kotlin Multiplatform was designed to address.
When expanding the presence of your application to iOS (and even into a desktop and web app, code for KMM needs to be refactored. ), your development team need to prepare the architecture with a multi platform in mind. It won't work out of the box.
You only want to share specific features or modules across platforms
With optionality in code sharing, you can limit the use of KMP to certain features or modules. This is exactly what the language learning app Memrise did when they elected to only keep the logic, network communication, and persistence layers in a shared codebase.
For Memrise, KMM was the most ideal choice for multiplatform development because it allowed for the sharing of logic that couldn't be moved to the backend without compromising the offline experience. In contrast to other cross-platform solutions such as React and Flutter, KMM allowed their technology team to share only a portion of the app while keeping the rest intact.
When it remains best to go native for select features
Although React Native and Flutter can provide features and functionalities similar to native development, there are still some features best done natively. This includes camera features, augmented reality, machine learning, and rich animations. With Kotlin Multiplatform Mobile, you can build these types of features through a native approach and write the code for the rest with KMM.
Similarly, if it seems best to capitalize (or be cautious) on new capabilities from a recent OS version, then Kotlin Multiplatform is the optimal choice. While the essential business logic can be shared, the user experience remains as close to the platform’s distinct environment.
Building and maintaining an app on multiple platforms
A decade ago, tech startups or companies just beginning their digital journey had to prioritize whether to create applications on either Android or iOS first. When still experimenting with a product idea or when resources are scarce, a lot of businesses and organizations, even to this day, launch on only one platform and evaluate later on whether it’s worth the investment to build on another.
Because of Kotlin Multiplatform, being omnipresent on multiple platforms has become much more affordable. With KMP, businesses no longer require a full complement of specialists for each platform. At the same time, building and managing apps on different devices and operating systems is now faster and less risky. Kotlin Multiplatform isn’t just a technological innovation but a win for the business side of any company with a digital presence.