This tutorial teaches you how to set up and run your first Compose Multiplatform project on a Mac. I am using a Mac because Windows cannot run iOS apps. So, to develop apps for both Android and iOS, using Compose Multiplatform on a Mac is preferable.
KMP Compose Multiplatform First Project Setup & Run Guide for Android iOS
What is Compose Multiplatform?
Compose multiplatform is a UI framework created in Kotlin and developed by JetBrains to develop Android, iOS, desktop, and web apps using a single codebase. It is similar to Flutter and React native but faster because in Compose multiplatform we can integrate native code directly which is platform-specific, Though it is faster.
Prerequisites to run Compose Multiplatform:
JAVA – JDK
Android Studio as IDE
Kotlin Multiplatform Plugin Installation in Android Studio
SDK Manager for Android development
AVD Manager to create an Android virtual device(Simulator)
Xcode – to develop and run iOS apps.
Cocoapods for iOS
iOS simulator – to run iOS app
Kotlin composes multiplatform projects.
1. Download & Install Java
Visit Java Archive Downloads and download the Java 18.0.2 version for your MAC OS. After downloading, it should look like this.
Double-click on the dmg file and start the installation.3. Follow all the steps and install Java 18.0.2.1 JDK in your MAC OS.
2. Setup Android Studio for Compose Multiplatform KMM:
Visit developer.android.com/studio and download the latest version of Android Studio. At the time of making this tutorial Android Studio Ladybug is present. When you download Studio, it will ask if your MAC chip is Intel or Apple silicon. Choose your chip type and download.
After downloading Android Studio your setup should look like this.
Drage Android Studio to Applications.
After successfully installing, Goto Apps and opening Android Studio.
Allow all the permissions and Android Studio Installation Setup Wizard to open, Click on Next to continue
Select the Standard option from the radio button and click on Next.
On the next screen, it will show you the default installation components. Click on Next again to install them.
Accept the license agreement and click Finish to install.
Wait for a few minutes to download all the essential components for Android Studio. It depends on your internet connection speed. Click on Finish.Now your Android Studio is installed and ready to use.
3. Install the Kotlin Multiplatform plugin in Android Studio
Click on Plugins.
Search for the keyword “Kotlin Multiplatform,” select the first result, and click the Install button to install the plugin.
Now it will ask you to Restart the IDE. Tap to restart and your AndroidStudio is ready to start development in Kotlin compose multiplatform mobile.
AVD – Android virtual devices are simulators that test Android apps. To create your first AVD click on More Actions.
Click on Virtual Device Manager.
Now by default a virtual device is created but I prefer not to use it and create your own with your custom configuration. So click the 3 dotted menus present at the End of the virtual device.
Click on Delete to delete the existing simulator. It will ask for confirmation Press on the Yes button.
You can create an Android simulator with your own configuration now. Click on the “Create Virtual Device” link.
Select any Android device from the list, I am using Pixel 6 because it is faster than other devices.
You have to download the latest stable Android version from the AVD download manager. I am downloading Android 14 for now but you can also download the latest versions.
Wait from few minutes as it will download and install the Android version in your system.
After you have downloaded an Android version, that version will be highlighted. Then, select it and press the “Next” button.
Set your Simulator name and click on Advanced Settings.
On the next screen, You can set RAM for your AVD, Heap memory size, Internal storage size, SD card size, and Un-checkable device frame.
Your AVD has been successfully created. Click on the Play button to start the Android Virtual Device.
Wait for a few minutes and Your Android simulator will be started. Let the Android emulator run in the background.
5. Installing Xcode and configure MAC for iOS development
Click on the App Store icon.
Find Xcode in the search box and click on the Get button to install Xcode.
After installing Xcode, We have to download & install command line tools for XCode. So open your Terminal and type “xcode-select –install” command.
The next step is to download Cocoapods. Pods are used to download and SYNC dependencies in iOS projects. To download the Cocoapods first you have to download Homebrew. Open your terminal and execute this command to download and install Homebrew first.
/bin/bash-c"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Execute this command to install Cocoapods
brew install cocoapods .
6. Download & Configure the first KMP compose multiplatform Android project:
After download the project zip file, Extract it and open the project in Android Studio
Select your KMP project and click on Open.
It will ask you to Trust and Open the project, Hit the Trust Protect button. Now your KMP project will open in Android Studio. Wait from few minutes as it will download Gradle and dependencies for this project and Sync the Gradle.
Click on the Play button present at the front of composeApp to run your KMP project in the Android simulator.Wait for a few minutes and your KMP project will be launched in the Android simulator.
7. Install Kotlin Multiplatform Plugin in Android Studio
Open Android Studio.
Click on Plugins, Search for Kotlin Multiplatform, and click on Install.
After successfully installing the plugin, Restart the Android studio.
8. Run KMP project in iOS Simulator from Android Studio
Click on the drop-down arrow.
Click on Edit Configurations.
Click on the PLUS button.
Select the iOS application from the list.
Enter your App Name, and Select the Xcode project file from your project folder. This file will be present in the iOS folder.
Now click on the Play button in Android Studio and your iOS app will be launched in the iOS simulator.
Hope you have liked my tutorial on the KMP installation guide. If you face a problem on any step feel free to comment and I will reply to you.