Setting up a working Kotlin Multiplatform Mobile development environment in M1 Macs

Yashar
4 min readJun 16, 2021

--

Updated on 07/03/2021 to reflect few new changes. Including the used JDK version and the ability to run Xcode natively.

If you were lucky enough to get your hands on Apple’s M1 Mac machine, you may have been unlucky enough to get stuck on some of the annoying developer experience that comes with it.

One of many cryptic error examples

I went through just that trying to get Kotlin Multiplatform Mobile (KMM) working on my machine. This ended up costing me about a day to figure out what was going on. I hope this post can save you some time and pain that I had to go through.

TLDR:

  1. Make sure you are not using a JDK for Apple Silicon.
  2. Confirm the non-arm64 JDK is being used in the KMM project directory.
  3. Open iOS module in Xcode, not in Android studio.
  4. Exclude arm64 for simulator architecture both from your project and the Pod project. If you can successfully build and run the iOS project, stop here.
  5. If #4 didn’t do the trick, toggle Xcode to open using Rosetta, not in native M1 compatible mode.

Using the correct version of JDK

When I got my M1 machine, I set up both my Android studio and JDK used by it to take full advantage of the Apple Silicon. Meaning I was using the arm64 preview version of the Android Studio and using Azul Zulu (11.0.11+9)JDK which has native support for the arm64 architecture.

Turns out, while using the preview version of Android Studio is fine, you need to use x86_64 JDK. This is because the Kotlin/Native compiler does not support Apple Silicon at this time.

You can use useful tools like jenv to have multiple JDKs installed on your machine. Just make sure you have x86_64 JDK installed and are using that for your project. I used Java SE 16.0.1.

Chamika Kasun has written a great post on how to do this using jenv:

Build the project using the correct JDK

We want to make sure everything is built and ready to be used by the iOS project when we open it in Xcode. To build it, first, go to the root KMM folder and double-check you are using the correct JDK.

java -version command will show you the JDK version in use

Then simply build by writing ./gradlew build. Hopefully, you are seeing BUILD SUCCESSFUL the message once it’s complete.

Exclude arm64 for simulator architecture

Before resorting to the rather crappy experience of running Xcode through Rosetta, try excluding the arm64 for simulator architecture from your project.

To do so, you need to navigate to the Build Settings of your project and add the value arm64 to the Excluded Architectures.

Build Setting of the TARGETS

Hit run and see if the project builds successfully. If it did, congratulations! You can stop here.

This workaround seems like hit or miss, so if it didn’t work, give the next step a try.

Use Xcode via Rosetta

If you stop here and try to run the iOS project either through Android Studio or Xcode, you will encounter another issue that may look something like this:

There are some suggested fixes like excluding arm64 architecture in Xcode build settings, but none of them worked for me. In the end, what solved my issue was running Xcode through Rosetta.

You can do that by checking the “Open using Rosetta” checkbox in Xcode’s info menu (you can get there by selecting Xcode and hitting command + i).

Once it’s checked, go to the iOS module within your KMM project folder, and open iosApp.xcodeproj if your project does not use cocoapods or iosApp.xcworkspace if it does.

Once the project is opened and ready (will take longer than usual due to the translation layer from Rosetta 😢), you should be able to hit run and see everything working.

--

--