How to Create a Kotlin Multiplatform Library

Photo of Krzysztof Kansy

Krzysztof Kansy

Updated Jul 23, 2024 • 5 min read
kmm_library

This article will focus on creating a multi-platform mobile project for Android and IOS platforms.

We will go through two scenarios: the first is to create a project from scratch with complete configuration, and the second shows how to add an iOS module to an existing Android project.

Requirements for creating a Kotlin Multiplatform library:

We will be using XCFramework as a way to add dependencies to the iOS applications.

First Scenario: Creating an application from scratch

  • Create Project and configure Gradle file

Sample of how to create an application from scratch

A short note: the iOS module is already automatically configured.

  • Launching the application

Launching the Application

Configure the iOS simulator

Sample of how to launch the application on both platforms

Second Scenario: Add iOS Module to existing Android application

  • Create Project and configure Gradle file

Sample of how to add the module to an existing project

  • Link extra module to iOS app

Sample of how to link added module to iOS app

More details: Multiplatform Gradle Plugin Improved for Connecting KMM Modules | The Kotlin Blog

You may need to clear the cache in Android Studio and XCode.

Building a Kotlin Multiplatform library

We presented to you the project requirements and two scenerios to create a Kotlin KMM library. We hope this article can help you speed up your multiplatform projects. If you are interested in learning more about Kotlin Multiplatform you may read How to Handle Resources in Kotlin Multiplatform.

Photo of Krzysztof Kansy

More posts by this author

Krzysztof Kansy

Former Android Developer at Netguru
Kotlin Multiplatform Guidelines  Architectural aspects of multiplatform projects developed in Kotlin Read now!

We're Netguru

At Netguru we specialize in designing, building, shipping and scaling beautiful, usable products with blazing-fast efficiency.

Let's talk business