If you’ve spent years polishing an enterprise application for Android and now you’ve been asked to bring the project to Apple users as well, you’re probably wondering if you have to throw all your work out the window. The good news is that Kotlin Multiplatform (KMP) is here to save the day, allowing us to reuse business logic without having to write the same code twice in different languages.
This isn’t a magic tool that does all the work on its own, but rather a smart strategy for sharing the data and domain layer . Essentially, we move what’s common to both platforms to a central location and let each system manage its own interface, allowing us to maintain the quality of a native app but with the efficiency of unified development.
How to set up the shared module from scratch
To get off to a good start, the easiest thing to do is take advantage of the official tools. If you use Android Studio Meerkat and have the Gradle plugin version 8.8.0 or higher, you’re in luck thanks to the Kotlin Multiplatform Shared Module template . This option automates all the basic configuration so you don’t have to deal with the configuration files.
The process is quite intuitive: go to File > New > New Module and select the KMP template. Here you’ll need to define the module name (which will also serve as the framework name on iOS) and the file package. Once you click Finish, let Gradle work its magic by synchronizing the project. You’ll see that platform-specific folders are created, along with a common space called commonMain , which is where the real work happens
Integrating shared logic into Android
Creating the module is only half the battle; now you need to tell your Android app to use that code. The wizard doesn’t do this automatically, so you must add the dependency manually to your Gradle file. The usual way to do this is to add `implementation(project(“:shared”))` within the dependencies block.
If you’re one of those who have enabled Gradle’s Type-safe project accessorsprojects.shared , you can simplify things by using `link` . Once linked, your Android app will be able to seamlessly consume everything you’ve programmed in `androidMain` or `commonMain` , integrating completely naturally into the workflow.
Configuration and deployment in the iOS ecosystem
This is where things get interesting, since Swift doesn’t natively understand Kotlin. To make them work together, we need to generate a compiled binary framework . The Android Studio template already provides the build.gradle.ktsconfiguration file for the different Apple architectures, such as iosX64, iosArm64, and iosSimulatorArm64 .
By default, the framework is called `kotlin` sharedKit, although you can change this `xcfName` variable if you prefer a name more in line with your brand. To tell Xcode what to do, you need to add a script execution phase called `Compile Kotlin Framework` . It’s vital that this script runs before compiling the Swift source code so that the Kotlin code is already available when Swift looks for it.
To verify that everything works, simply go to the ContentView.swift file in Xcode, import the library sharedKit, and call a function from the shared module, such as the classic one platform(), to confirm that the app recognizes that it is running on iOS .
Jumping to Kotlin 2.0 and Compose Multiplatform
If you want to upgrade to Kotlin version 2.0, there are a couple of tweaks you’ll need to make. First, update the version in your libs.versions.toml file , and don’t forget to add the folder to your .gitignore.kotlin file to avoid uploading unnecessary junk files to the repository.
A key change is the Compose compiler , which is now a built-in Kotlin plugin. You need to add it org.jetbrains.kotlin.plugin.composeto your version catalog and apply it to the relevant build.gradle files. This allows you to remove the composeOptions block and take advantage of a much cleaner DSL for configuring things like strongSkippingMode .
Additionally, if you’re using KSP (Kotlin Symbol Processing) , be sure to update it to a version compatible with Kotlin 2.0 to avoid annoying compilation errors. If you already have experience with Jetpack Compose, you can adapt that code for Compose Multiplatform , allowing you to share not only the logic but also part of the user interface, although some specific details will still need to be adjusted to ensure a smooth experience on iOS.
Migrating an enterprise infrastructure to KMP involves organizing the code into a shared module, properly linking it to Android via Gradle, and configuring Xcode using iOS build scripts. Upgrading to Kotlin 2.0 simplifies Compose compiler management and optimizes the project structure, ensuring consistent domain logic and a platform-specific interface.