Get Started With Kotlin Multiplatform For Mobile

Introduction

Kotlin Everywhere! Kotlin is winning the hearts of developers worldwide due to its ability to make coding concise, cross-platform development, and fun. Kotlin Multiplatform simplifies the process of creating cross-platform applications using a single codebase and language, ensuring compatibility with various operating systems, including iOS, Android, macOS, Windows, Linux, watchOS, and more.

Kotlin

While Kotlin Multiplatform is still in beta, you can write code that can be shared between platforms, and you can also write platform-specific code when you need to implement a native UI or work with platform APIs.

Kotlin Multiplatform

Let's now build a mobile application for both Android and iOS using Kotlin Multiplatform.

Set up an environment

To set up the Kotlin Multiplatform Environment, we need some tools to install.

  • Android Studio
  • Xcode
  • JDK
  • KMM plugin 

If you want to test your app in iOS, then Xcode is needed, and to successfully build and test your iOS application, you need the following tools.

1. Install the homebrew

brew install kdoctor

2. After the installation is completed, call KDoctor in the console:

kdoctor

 Note. These are the steps for Mac only.

Create your first cross-platform app

Now it is time to create and set up our first multiplatform project. So, without further waiting, let's get started.

Firstly if you don't have the KMM plugin installed on Android Studio, open your Android Studio select the plugins tab, search for "Kotlin Multiplatform Mobile" and Install it.

Android Studio

After successfully Installing the plugin, apply it and restart your Android Studio.

In Android Studio, select File | New | New Project. Select Kotlin Multiplatform App in the list of project templates, and click Next.

New Project

Specify a name for your first application, and click Next.

New Kotlin Application  

In the iOS framework distribution list, select the Regular framework option.

Regular framework

Keep the default names for the application and shared folders. Click Finish.

Run your application

We can run this application on Android and iOS. Let's see how 

Run on Android Devices

To run on Android devices, you can create an Android Virtual Device (AVD), or you can opt for any physical device to Run. Choose the Android app from the run configurations, select the Android device, then click on the run.

Run on Android Device

Run on iOS Devices

Launch XCode and launch any simulator in a separate window. Now open Android Studio, select iosApp in the list of run configurations, and click Run.

Run on IOS

Summary

Kotlin Multiplatform is going to revolutionize the way the market industry perceives the Kotlin language. Hopefully, by the end of the year, the Kotlin Multiplatform beta will achieve stability. Compose Multiplatform is set to play a crucial role in this transformation by enabling the sharing of UI capabilities across application logic. This approach allows you to design your user interface once and leverage it across all your target platforms, including iOS, Android, desktop, and web. Additionally, we anticipate various significant changes in Kotlin Multiplatform in the upcoming year, so stay prepared for exciting developments. Thank you!


Similar Articles