This is the first part of the Getting started with Kotlin Multiplatform for mobile tutorial:
Set up an environment
Create your first cross-platform app
Update the user interface
Share more logic
Wrap up your project
Before you create your first application that works on both iOS and Android, you'll need to set up an environment for Kotlin Multiplatform Mobile development.
To write iOS-specific code and run an iOS application on a simulated or real device, you'll need a Mac with macOS. This cannot be performed on other operating systems, such as Microsoft Windows. This is an Apple requirement.
Install the necessary tools
We recommend that you install the latest stable versions for compatibility and better performance.
|Android Studio||You will use Android Studio to create your multiplatform applications and run them on simulated or hardware devices.|
Most of the time, Xcode will work in the background. You will use it to add Swift or Objective-C code to your iOS application.
We generally recommend using the latest stable versions for all tools. However, Kotlin/Native sometimes doesn't support the newest Xcode right away. If that's your case, install an earlier version of Xcode.
|JDK||To check whether it's installed, run the following command in the Android Studio terminal or your command line:
|Kotlin Multiplatform Mobile plugin||In Android Studio, select Settings/Preferences | Plugins, search Marketplace for Kotlin Multiplatform Mobile, and then install it.|
The Kotlin plugin is bundled with each Android Studio release. However, it still needs to be updated to the latest version to avoid compatibility issues.
To update the plugin, on the Android Studio welcome screen, select Plugins | Installed. Click Update next to Kotlin. You can also check the Kotlin version in Tools | Kotlin | Configure Kotlin Plugin Updates.
The Kotlin plugin should be compatible with the Kotlin Multiplatform Mobile plugin. Refer to the compatibility table.
Check your environment
To make sure everything works as expected, install and run the KDoctor tool:
KDoctor works on macOS only.
In the Android Studio terminal or your command-line tool, run the following command to install the tool using Homebrew:
brew install kdoctor
After the installation is completed, call KDoctor in the console:
If KDoctor diagnoses any problems while checking your environment, review the output for issues and possible solutions:
- Fix any failed checks (
[x]). You can find problem descriptions and potential solutions after the
- Check the warnings (
[!]) and successful messages (
[v]). They may contain useful notes and tips, as well.
You may ignore KDoctor's warnings regarding the CocoaPods installation. In your first project, you will use a different iOS framework distribution option.
- Fix any failed checks (
Possible issues and solutions
JAVA_HOME. This environment variable specifies the location of the Java binary required for Xcode and Gradle. If so, follow KDoctor's tips to fix the issues.
Error: can't grab Xcode schemes. If you encounter an error like this, in Xcode, select Settings/Preferences | Locations. In the Command Line Tools field, select your Xcode.
Kotlin Multiplatform Mobile plugin
Make sure that the Kotlin plugin is updated to the latest version. To do that, on the Android Studio welcome screen, select Plugins | Installed. Click Update next to Kotlin.
You can also check the Kotlin version in Tools | Kotlin | Configure Kotlin Plugin Updates.
Make sure you have all the necessary tools installed:
In the next part of the tutorial, you'll create your first cross-platform mobile application.