Integrating iOS into the Fold: Generating an IPA for Compose Multiplatform Projects

Integrating iOS into the Fold: Generating an IPA for Compose Multiplatform Projects

Intro

With Kotlin Multiplatform 1.5.10 going stable, now is as good of a time as any to dive into Compose Multiplatform.

With my background in Android development and some familiarity with Jetpack Compose, Compose Multiplatform is a great solution for when I need a cross-platform solution for UI + business logic to be shared across the targets that I'm interested in; Android, iOS, and Desktop.

However, my unfamiliarity with the intricacies of iOS and XCode has left me scratching my head from time to time. Don't get me wrong, general development using Compose Multiplatform has been great! I am usually working within Android Studio writing Kotlin, two tools I am extremely familiar with, but recently I wanted to distribute a test version of my iOS app on Firebase for friends and family to test, and that process took some time for me to understand. Today, I wanted to document some of my learnings so it can be helpful for others as well.

Problem

Using my Android knowledge and some Googling, I have found the generally accepted version of how to generate an IPA file is to open XCode, select your relevant destination (in this example, I am choosing any iOS device, arm64) and select Product -> Archive.

However, when I do that, I receive an error message about needing Java 17 when I am using Java 16. As an Android engineer, I am aware that projects using AGP 8.0+ are required to use Java 17, however, I am never install Java 16 on my system. I am truly baffled by where that error was coming from. My guess is that XCode must ship with some internal version of Java? What is even more confusing is that I have my Java home set correctly in my .zshrc file and when I input java -version in the terminal, I am met with what I expect to see, Java 17.

joe@Joes-MacBook-Pro ~ % java -version
openjdk version "17.0.7" 2023-04-18 LTS
OpenJDK Runtime Environment Corretto-17.0.7.7.1 (build 17.0.7+7-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.7.7.1 (build 17.0.7+7-LTS, mixed mode, sharing)

I had a hunch that for some reason, XCode wasn't aware of my path variables.

Solution

I've run into situations before with GIT GUI clients where opening them via the finder/dock doesn't allow for the application to be aware of your environment/path variables. To work around that, from previous issues, I've learned that opening your program via the command line with make the application aware of your environment/path variables.

So in the root of my project I executed open iosApp/iosApp.xcodeproj which should open XCode with your iOS project. After selecting Product -> Archive again, I was finally able to generate the archive for my project.

I hope this helps!