KMP Compose Multiplatform First Project Setup & Run Guide for Android & iOS

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

KMP Compose Multiplatform First Project Setup & Run Guide

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:

    1. JAVA – JDK
    2. Android Studio as IDE
    3. Kotlin Multiplatform Plugin Installation in Android Studio
    4. SDK Manager for Android development
    5. AVD Manager to create an Android virtual device(Simulator)
    6. Xcode – to develop and run iOS apps.
    7. Cocoapods for iOS
    8. iOS simulator – to run iOS app
    9. Kotlin composes multiplatform projects.

1. Download & Install Java

  1. Visit Java Archive Downloads and download the Java 18.0.2 version for your MAC OS. After downloading, it should look like this.Java 18 Download For KMM
  2. Double-click on the dmg file and start the installation.Java_Introduction3. Follow all the steps and install Java 18.0.2.1 JDK in your MAC OS.JAVA INSTALL DONE

2. Setup Android Studio for Compose Multiplatform KMM:

  1. 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.
  2. After downloading Android Studio your setup should look like this.ANDROID STUDIO SETUP
  3. Drage Android Studio to Applications.Android Studio app
  4. After successfully installing, Goto Apps and opening Android Studio.Android Studio in Launchpad MAC
  5. Allow all the permissions and Android Studio Installation Setup Wizard to open, Click on Next to continue Welcome android studio
  6. Select the Standard option from the radio button and click on Next.
  7. On the next screen, it will show you the default installation components. Click on Next again to install them.Android studio default components
  8. Accept the license agreement and click Finish to install.Android studio license agreement
  9. Wait for a few minutes to download all the essential components for Android Studio. It depends on your internet connection speed. Click on Finish.Android Studio downloading componentsNow your Android Studio is installed and ready to use.Android Studio Welcome Screen

3. Install the Kotlin Multiplatform plugin in Android Studio

  1. Click on Plugins.Add plugins in Android Studio
  2. Search for the keyword “Kotlin Multiplatform,” select the first result, and click the Install button to install the plugin.KMP Android Studio Plugin
  3. 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.

4. Creating AVD Manger(Android Virtual Device – Simulator)

  1. AVD – Android virtual devices are simulators that test Android apps. To create your first AVD click on More Actions.More Actions
  2. Click on Virtual Device Manager.Virtual Device Manager
  3. 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.AVD Manager menu
  4. Click on Delete to delete the existing simulator. It will ask for confirmation Press on the Yes button.Delete AVD Manager
  5. You can create an Android simulator with your own configuration now. Click on the “Create Virtual Device” link.Create AVD Manager

  6. Select any Android device from the list, I am using Pixel 6 because it is faster than other devices.Pixel 6 AVD
  7. 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.AVD System Image
  8. Wait from few minutes as it will download and install the Android version in your system.Android Version Downloading
  9. After you have downloaded an Android version, that version will be highlighted. Then, select it and press the “Next” button.Android Upside down cake
  10. Set your Simulator name and click on Advanced Settings.AVD Manager Settings
  11. 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.AVD RAM size
  12. Your AVD has been successfully created. Click on the Play button to start the Android Virtual Device.Start AVD
  13. 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

  1. Click on the App Store icon.Apple app store
  2. Find Xcode in the search box and click on the Get button to install Xcode.Download Xcode
  3. After installing Xcode, We have to download & install command line tools for XCode. So open your Terminal and type “xcode-select –install” command.MacOS Terminal
  4. 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)"
  5. Execute this command to install Cocoapods brew install cocoapods .

6. Download & Configure the first KMP compose multiplatform Android project:

  1. Open kmp.jetbrains.com and create your first KMP project. My First KMP Project
  2. After download the project zip file, Extract it and open the project in Android StudioOpen KMP project
  3. Select your KMP project and click on Open.Open KMP project
  4. 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. KMP SYNC
  5. Click on the Play button present at the front of composeApp to run your KMP project in the Android simulator.Run KMP appWait for a few minutes and your KMP project will be launched in the Android simulator.KMP Compose Multiplatform First Project Setup & Run Guide

7. Install Kotlin Multiplatform Plugin in Android Studio

  1. Open Android Studio.Android Studio Welcome Screen
  2. Click on Plugins, Search for Kotlin Multiplatform, and click on Install.KMP Android Studio Plugin
  3. After successfully installing the plugin, Restart the Android studio.

 

8. Run KMP project in iOS Simulator from Android Studio

  1. Click on the drop-down arrow.
  2. Click on Edit Configurations.Edit KMP Configurations
  3. Click on the PLUS button.
  4. Select the iOS application from the list.iOS Application
  5. Enter your App Name, and Select the Xcode project file from your project folder. This file will be present in the iOS folder.iOS Config
  6. Now click on the Play button in Android Studio and your iOS app will be launched in the iOS simulator.KMP Compose Multiplatform First Project Setup & Run Guide

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.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *