Mobile app development – Kotlin multiplatform module “KMM” - One more way to achieve code reusability.

Mobile app development – Kotlin multiplatform module “KMM” - One more way to achieve code reusability.

There are many ways to develop a mobile application. There is a new way that I came across lately, so thought of writing my view on that.

Let’s take a quick look at existing ways to develop a mobile app

1.??Native

No alt text provided for this image

This is still popular wherein we write the code in Swift for iOS and in Kotlin for Android. This is popular because of its performance and kind of risk-free. But cost-wise need to maintain two code bases separately for 2 platforms (Android & iOS)

2.??Cross-platform

No alt text provided for this image

Many platforms have emerged to write the code in one language and generate the platform-specific application. React Native & Flutter are popular. These are now stable platforms, and many applications are being built using this. The learning curve is a downside with these platforms.

3.??Hybrid

No alt text provided for this image

Don’t see much traction for these platforms. (E.g., Ionic) This could be because these platforms use web technologies and run the application in WebView shell. Mostly these platforms are declining because of performance-related issues.

So, what’s new now?

No alt text provided for this image

Recently I came across the “Kotlin multiplatform module” (KMM) concept.

How does it work?

Write the complete code in the Kotlin programming language. Android studio can be used as an IDE and add Kotlin multiplatform plugin to it that’s it, ready to go.

But this could be useful for new applications what about the existing app?

Kotlin multiplatform module (KMM) library

Let’s take an example that you are planning to add a new feature into the existing app and want to use KMM then?

  1. Create a KMM project as a “Library” (Android studio allows this to create KMM library post-KMM plugin installation)
  2. Write the complete code in this library project. The additional advantage is if platform-specific code is to be added to the library then this is easy, KMM allows that.
  3. Once done and tested then export the iOS / Android specific libraries from this library project and add them as a dependency in our existing application.
  4. In the future, if changes are required then only library code will change which is common for both Android & iOS.

What are the practical advantages of this platform?

  1. Kotlin is the language so no learning curve for Android developers. In the case of React native, both Android & iOS developers have to learn the JavaScript framework.
  2. As this is native no performance issues
  3. Don’t need to convert the existing app, creating a common KMM library and integrating with the existing app is quite possible.
  4. Business logic that is independent of the platform can be pushed to the KMM library. (Ideally business logic shall go in API but if API model is not possible due to some constraints, then KMM could be the option)
  5. We get Android studio as IDE, and it is mature and comes with a whole lot of features. The IDE can launch both Android & iOS simulators both.

As a POC it’s worth giving a try on the “Kotlin multiplatform module” approach.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了