· 6 min read Posted by Kevin Galligan
Ideal iOS KMP Setup
The iOS developer experience with KMP is a “work in progress”. Xcode itself is not the most extensible tool, and for iOS developers, the Kotlin and Gradle ecosystems are generally new territory. There are many options and differing opinions on tooling. Touchlab has been helping teams adopt KMP since KMP was launched, and have developed some of the best tooling options available.
This setup represents our current best-practice for iOS KMP development.
Install a JVM
You’ll need a modern JVM to build Kotlin. Apple doesn’t directly distribute a JVM, or at least not a modern one, so we’ll be using some developer tools to install and manage your JVMs.
SDK Man
First up, install SDK Man. It’s a “Software Development Kit Manager”.
Open a terminal and run the following:
curl -s "https://get.sdkman.io" | bash
The install script will print instructions to configure your local environment to use SDK Man. Make sure to follow those so JVM tools are available on your PATH
environment variable.
Run the following to confirm successful installation.
sdk version
Install a JVM
Install a compatible JVM version. Most Android and Kotlin dev currently uses Java 17 to build. You can select a JVM from various publishers (they all are forks of OpenJDK, but different vendors optimize various parts). We generally recommend either Amazon Corretto or the main OpenJDK distributions.
Run the following in terminal:
sdk install java 17.0.11-amzn
When the install is complete, you’ll see the following prompt:
Do you want java 17.0.11-amzn to be set as default? (Y/n): Y
Type ‘Y’, unless you have a really good reason not to :)
Xcode Version
KMP is generally tested on recent versions of Xcode. While minor version updates of Xcode generally work with KMP, there can be a lag after major Xcode updates. This lag is generally not long, but you’ll need to update your Kotlin version.
You might want to have multiple versions of Xcode installed. Some of our devs (myself included) use the Xcodes App to download and manage Xcode installs. It requires you to log into your Apple Developer account, which can be a security risk. However, Xcodes is open source and generally trusted. This is more of a personal comfort decision.
At the time of writing, I am on Xcode 15.3.
Kotlin Xcode Plugin
Touchlab provides the Xcode Kotlin Plugin. This tool uses the standard Kotlin LLDB integration for the actual debugging, but configures Xcode to “understand” Kotlin. Specifically, it provides source code styling for Kotlin, and allows you to set breakpoints in Xcode directly.
We have a Homebrew tool to run the plugin install and configuration. In a terminal run:
brew install xcode-kotlin
Once install, run:
xcode-kotlin install
Xcode doesn’t allow “Plugins”
At one time there was a thriving, if unofficial, ecosystem of 3rd party Xcode plugins. Apple shut down plugin access to Xcode for security reasons, so most Plugins do not work. However, our plugin does nothing that would be a security issue, and those parts of the Xcode Plugin system are still available to outside developers.
SKIE - Swift/Kotlin Interface Enhancer
The interface provided by KMP to Swift is Objective-C. While this is often blamed for the loss of Kotlin features, the reality is that Kotlin and Swift are simply different languages. To “bridge” modern Kotlin features to Swift, and provide a more pleasant and usable Swift-facing API, we have built SKIE.
You can read more about it’s detailed features. In summary, SKIE bridges some modern Kotlin language features to Swift equivalents, and provides automatic bidirectional support for Kotlin Coroutines to Swift async structures.
For new projects, we highly recommend having SKIE enabled by default. For existing code bases, follow the SKIE Migration Guide. SKIE’s design attempts to be a drop-in replacement where possible, but it unavoidably changes types, so existing code may not work if SKIE is applied to your whole project. You can incrementally apply SKIE as necessary.
Android Studio or Intellij
If you plan to edit Kotlin or build the Android version of apps, you should install the Android sdk, and either Android Studio or Intellij. Android Studio is generally the easier option, as it’ll walk you through installing and configuring the Android sdk. Intellij tends to have newer Kotlin plugin versions. (I have both installed)
The easiest way to install these tools is with the JetBrains Toolbox.
Kdoctor
JetBrains publishes a tool to check your environment called “Kdoctor”. Installing and running that will help check config and diagnose issues.
Testing your setup
With these tools installed, you should be able to start building apps with KMP. There are many KMP sample apps available, but we’d recommend ours, as it has the Xcode project configured with the Kotlin source available for debugging.
CocoaPods
KaMPKit uses CocoaPods to build KMP. We generally recommend using a different method currently, and KaMPKit should be updated. However, many KMP apps use CocoaPods locally, so it’s not a bad idea to get that installed :)