The smartphone in your pocket or that is sitting on your desk are impressive pieces of hardware in their own right, and keep you connected to your life and the people within it. But what is really impressive is the operating system running on them because that is what makes the real magic happen.
These operating systems are all different and as such, require different frameworks, tools, and languages for application development. However, today, I am going to focus on just one, Kotlin. That’s is because it isn’t very often a programming language that gets adopted as a specialized framework for the Android platform, only to evolve to now support iOS. Needless to say, Kotlin is well on the road to being a widely-used, multiplatform programming language.
But, I think I am getting ahead of myself. Let’s take a step back and start at the beginning.
Kotlin and Kotlin/Native: A Brief Overview
Kotlin came into existence in July 2011, a product of JetBrains. However, it wasn’t until May 2017 that Google announced its support of Kotlin, over a year after its first official stable version (Feb 2016). Since then, Kotlin has become the preferred language for Android application development. Slowly, but steadily, it’s also growing popular for other platforms, including iOS application development. Kotlin/native is used for this purpose, which compiles the Kotlin code to native binaries that run without any virtual machine. Kotlin/native is an LLVM (Low-Level Virtual Machine) based backend for Kotlin compiler that converts the Kotlin code to LLVM Intermediate Representation (IR). The LLVM compiler understands that Intermediate Representation and creates binaries for multiple platforms.
Both iOS and Android platforms have different approaches when it comes to native application development. But now Kotlin has made it comparatively easy by supporting both. This saves the additional effort of developers in learning two different programming languages [Java & Swift]. Developers can now develop the business, network, and repository layer in Kotlin as a dependency module for native applications. iOS and Android apps can use the same libraries, saving them time and effort in creating two. The below diagram shows the separated layers of the application architecture while following the Kotlin based custom developed multiplatform library.
android app view fragment and iOS app view UIViewController have common presenter, interactor: business logic, repository: persistence (sqlite, shared Pref), repository: networking (HTTP, serialization).
Benefits of Kotlin in Multiplatform App Development
The ability to share code between mobile platforms is undoubtedly one of the most important and appealing use cases of Kotlin, however, they extend beyond that. Here are a few of the more commonly experienced benefits of developers cite from using Kotlin:
- It’s a timely and cost-effective solution to develop common layers in your mobile application development architecture
- Two-thirds of the source code resides inside the shared Kotlin library, making management easy
- Provides bi-directional interoperability along with modules and libraries that can all be used with Objective-C, Swift, and Java
- Significantly improve time to market for new products by developing the multiplatform supported core modules of your application
- Compiles the iOS and Android native platform SDKs/binaries, with limitations in comparison to other multiplatform frameworks available in the market
- Developers only have to write one unit test and reuse it to validate the application’s business logic on both iOS and Android platforms
- No lagging behind native platforms: Software developers don’t have to wait until vendors or the mobile community add support for new features
Key Challenges With Kotlin
Initially, every programming language starts with its own set of challenges, and the one reason this will keep happening as it takes a community to help refine. As a new programming languages’ ecosystem builds up, so to will increase its adaptability, reliability, and function. However, this can take months, if not years. Considering this, developers might encounter some challenges while using Kotlin for iOS and Android app development and here are a few to be wary of:
- As a comparatively new platform for iOS app development, it’s not without challenges and issues. It lacks a mature ecosystem for iOS app development which can create obstacles for developers looking for outside the box solutions.
- Developers need to understand both the iOS and Android platforms to utilize for multiplatform development effectively. It is a daunting task to understand better both the architectured required to make effective use of Kotlin and reduce the time and effort costs.
- Both iOS and Android have their own set of recognized design patterns that are being followed globally as a standard practice, like VIPER in iOS and MVVM in Android app development. Application developers might encounter the hurdle of figuring out the best suitable app development pattern while developing the core modules with Kotlin for the usage in multiple platforms.
Does Kotlin Makes App Maintenance Easier?
It’s a common understanding that an application is easier to maintain if there is a higher portion of shared code. For example, if an application has core modules developed in Kotlin that are shared across the platform and cover 80% of the business logic. Now, let’s say there is a change in the requirement to upgrade the repository layer and add a new collection in the database schema. The developers in such a case only have to manage this change from the centralized Kotlin based shared library. It results in reflecting the difference in both iOS and Android platforms, which eventually saves time and cost effort for the business. So in short – yes
Take away
The critical point to focus on here is how rapidly technology is changing and how it benefits mobile app development. We can confidently predict that, soon, Kotlin/native will be one of the key contributors in multiplatform mobile app development. The main advantage Kotlin/native has over other frameworks is its operability with Java and Swift. It also allows developers to develop the native iOS and Android applications using shared code. Sharing a significant part of the codebase between iOS and Android gives an experience of enhanced maintainability. This results in cost savings and enhanced value that all stakeholders, from developer to end-user, can feel.
The above was written in collaboration with Imran Mian, Vice President of Digital Transformation and Abrar Ahmed Sair, Senior Android Developer, both of mobileLIVE.