Kotlin Multiplatform Examples in Mobile Projects: Netguru Way
When it comes to developing mobile applications, many tools are available, including React Native Flutter, and progressive web app approaches. Meanwhile, native languages are evolving, with Jetpack Compose on Android and SwiftUI on iOS.
But what if you want to create a cross-platform mobile application that’s fully native and relies on shared code for business logic? Kotlin Multiplatform Mobile is an innovative technology we’ve been experimenting with.
Indeed, over the last two years, our Research & Development department has created several exciting and successful Kotlin Multiplatform examples, and following that, introduced KMM into Netguru’s software development process.
What is Kotlin Multiplatform Mobile (KMM)?
Kotlin Multiplatform Mobile is an SDK that’s used for cross-platform mobile applications. Using KMM, it’s possible to build multiplatform mobile applications and share aspects like core layers and business logic between Android and iOS apps.
Kotlin Multiplatform Mobile offers the combined benefits of creating native and cross-platform applications and is used by companies such as Philips, Netflix, Leroy Merlin, and VMWare. Check out KMM’s case studies for more info.
With Kotlin Multiplatform Mobile, It's possible to share up to 70% of code between Android and iOS applications. Why? Because the same business logic is pushed to each platform.
As such, customers benefit immediately from new code releases and updates, regardless of whether they use iOS or Android applications. The remaining 30% of code is for native-only features like the user interface (UI) or platform-specific implementations like augmented reality (AR) or virtual reality (VR).
Indeed, there are other cross-platform options such as Flutter and React Native. Let’s explore KMM and Flutter in more detail.
Kotlin Multiplatform Mobile vs. Flutter
So, in the KMM versus Flutter battle, who wins? There are pros to each tool, from KMM’s flexibility and native UIs to Flutter’s 100% shared codebase and its promotion of feature parity between apps. Of course, there are downsides to each too, from KMM’s relative newness (and lack of support) to the larger footprint of Flutter’s applications.
Pros of Kotlin Multiplatform Mobile
- KMM offers a “shared business, native UI” concept that’s useful for developers, because it means they don’t have to give up their preferred toolchains.
- KMM’s flexibility is a big selling point, enabling developers to share business logic code across different platforms, helping with speed and productivity.
- With KMM, because 70% of code is shared, if a bug is detected in the shared code, you only need to fix it in one place. With native development solutions, developers have to apply a fix in two places, because each platform has its own unique code.
Cons of KMM
- Kotlin Multiplatform is a relatively new SDK, meaning there aren’t as many developers using it as demand requires – yet.
- Because UI rendering is native with KMM, views for Android code and iOS code must be written separately, meaning more work for your development team than the likes of Flutter or React Native.
Pros of Flutter for cross-platform applications
- Flutter is easy to use. If your developers have coded with Swift, TypeScript, or Java, they'll be comfortable with Flutter's modern framework and able to build fully functional apps.
- Apps built in Flutter perform at pretty much the same level as natively-written applications.
Cons of Flutter
- Flutter’s ecosystem is comparatively limited, due to its niche language choice.
- Flutter is also a relatively new toolkit that’s still being developed. With that comes greater risk, compared to a more developed SDK.
- Flutter has fewer experienced developers than better-established platforms.
- The platform is missing advanced features, so it may not be ideal for complex apps and solutions.
- Because Flutter doesn’t use native widgets, published apps won’t update when a new version of Android or iOS is released, meaning extra work for developers to tweak and republish a new iteration of the application. Note: This is seen by some as an advantage, since iOS and Android applications won’t change without you realizing it.
There’s more to Kotlin Multiplatform Mobile (and Flutter) than the above lists. Next, we’ll take you through how KMM works in practice and how we use it at Netguru.
Netguru way: Kotlin Multiplatform Mobile applications in practice
KMM is a new technology that recently transitioned from its alpha version to beta. At Netguru, we decided to invest early as a way of extending native capabilities. When we think about KMM, we often compare it with Flutter or React Native, but the technology is actually the middle ground between native and cross-platform solutions.
Because KMM requires native user interface rendering – separate UIs for Android and iOS applications – that adds to the number of developers you need.
However, by sharing business logic across platforms and writing code only once (in the Kotlin language), you gain many advantages. The biggest? Developers aren't creating two apps; rather, one application for two platforms.
KMM vs other platforms |
||||
Type |
KMM |
Native Android & iOS |
React Native |
Flutter |
UI |
Native, separated |
Native, separated |
Common UI mapped to native components |
Custom rendering engine with common UI |
Business logic |
Common |
Separated |
Common |
Common |
Architecture |
Separation of business logic and UI by default |
Clear separation needs to be implemented |
Clear separation needs to be implemented |
Clear separation needs to be implemented |
Timeline of the project |
Like for Android apps. iOS is faster as only Ui is written |
All apps have own native timeline |
Same timeline for both apps |
Same timeline for both apps |
People required |
Android devs (more), iOS devs (less) |
Android and iOS devs |
React Native devs |
Flutter devs |
Possibilities |
Unlimited |
Unlimited |
Limited by performance of framework and additional work to add native features |
Limited by performance of framework and additional work to add native features |
From R&D to KMM in production
Our R&D team is broadening Netguru’s horizons by evaluating and adopting technology trends with high potential commercial value. We believe KMM falls into that category, and have started to use it across our projects, when appropriate.
Getting to that stage has taken two years: the first involved researching and validating KMM, and figuring out the skills our developers would need to use it effectively.
The next 12 months were about development – training our teams, preparing projects, more precise research, and gathering materials for the Growth team. Now, we’ve moved to the implementation phase. Below, we explore each step in more detail.
KMM: research phase
Here, we looked for common patterns and issues across various KMM R&D projects. We spent our time working on short and tailored single-problem projects with a narrow scope. That information helped us decide our investment and approach.
KMM: development stage
Next, we started the development phase – longer than the research step. It mostly involved team training and addressing questions we generated in the research stage. As part of that, we prepared specialized solutions, some of which were open-source.
This phase was less about specialized research, and more about approaching the KMM in big chunks and creating whole products to see how useful the technology is across different aspects, from architecture and code sharing to navigation.
Most of the training took place across the projects we outline in the next section. We worked with as many teams as possible and reviewed all approaches before moving on to the last phase: implementation.
KMM: implementation stage
Here, we trained not only our development teams, but also our business teams, regarding how KMM works and when it should be used. We showed them how KMM works across different mobile technologies (including the key differences), and highlighted the most beneficial scenarios to recommend KMM as a solution.
This was also the time to wrap up our internal KMM R&D projects and start sharing them with the world. We open-source and publish a part of the materials we create, so others can benefit from them (see below for links).
The wording in the above green boxes represents R&D codenames to identify projects internally, giving an overview of what we’ve been working on and how it links together.
We have a team of around 100 mobile engineers working every day with Kotlin, Swift, TypeScript, and Dart. Introducing Kotlin Multiplatform Mobile utilizes our existing Kotlin knowledge, but it differs in terms of architecture, approach to building apps, and even the possibilities the KMM platform introduces.
Netguru Kotlin Multiplatform examples
Since we started using KMM at Netguru, we’ve implemented it across several internal R&D projects. It can be used for multiple aspects of development on different platforms, and we’ve used it to build architecture for shared business logic, UI, and more. See below for additional info.
Kotlin Multiplatform example: Kana
Learning Japanese may like a big ask, but it’s achievable using mnemonics – a method for remembering something by associating it with something else.
We loved that idea, so we created the Kana R&D project using Kotlin Multiplatform Mobile for shared business logic and native languages for the user interfaces. A Redux-like architecture pattern helped us develop a simple, declarative view layer, minimizing the effort of using native controls and widgets, while allowing us to experiment with UI toolkit libraries such as Jetpack Compose and SwiftUI.
Kotlin Multiplatform example: Ecommerce furniture app
Given the global ecommerce growth rate was set to reach 9.7% in 2022, equating to $5.7 trillion sales worldwide, it’s no surprise so many companies choose to build ecommerce apps to reach their customers.
With that in mind, we decided to test out KMM for an ecommerce application. The codebase was fully written in Kotlin, with all business logic included in a common space.
The UI was created using native approaches –Jetpack Compose and SwiftUI. We also included complicated elements, like Augmented Reality (AR) to display the furniture in different settings. KMM allowed us to do that natively without any restrictions.
Composable Kotlin Multiplatform charts
To help our teams with future Kotlin Multiplatform projects, we created a library of chart composables. Platforms currently supported are desktop (Windows, Linux, and macOS) and Android. The chart types include:
These can be used to showcase comparative data or give statistics/numerical information in an interesting way for the end customer. These composables will help speed up development on future Kotlin Multiplatform projects.
KMM’s potential for mobile app development
Rather than being compared to and pitched against React Native or Flutter, KMM is more a competitor for native development. It delivers the benefits of native development while still allowing us to deliver new applications quickly.
Also, KMM’s common business logic enables us to reduce the number of bugs during coding, meaning we can keep platform-independent without writing code twice. Additionally, Kotlin Multiplatform Mobile doesn’t limit us from creating innovative features that may otherwise require platform-specific code and APIs.
Why? Because with KMM, it’s easy to switch between shared code parts to the native codebase, and write native code. Combined, these factors mean that KMM has a huge advantage over native development in terms of speed and flexibility. This keeps our developers happy and productive, and at the same time, means we bring better applications to customers more quickly – win-win.