Build Kotlin Multiplatform iOS apps on Windows
Gradle links the shared module, and Compose Multiplatform builds too.
Build the iOS app of a Kotlin Multiplatform project on Windows, install it on your iPhone and debug it. The iosApp project and your Gradle build scripts need no changes, and Compose Multiplatform works too. Set breakpoints in both Swift and Kotlin, and step from Swift into Kotlin.
Steps
Set up your environment
Install Android Studio as described in the Kotlin Multiplatform docs, then install the Kotlin Multiplatform plugin from its plugin marketplace.
Create a project
To use an existing project, open its root folder in VS Code with File > Open Folder…, or drag the folder into VS Code. Otherwise, create one with the Kotlin Multiplatform wizard in Android Studio or on the JetBrains website, select the iOS target, and open it in VS Code.
Run doctor
Do this first whenever you open a project for the first time. Doctor checks your Kotlin Multiplatform setup and prepares the iOS project. The first run downloads a few hundred MB and takes a while. Run it again after you upgrade Kotlin.
Use either of these
-
VS Code extension
In the title bar of the KXBuild view, open the ··· menu and run Doctor (fix environment).
-
Command line
> kxbuild doctor D:\work\mykmpapp\iosApp\iosApp.xcodeproj
Write code
The Swift code in iosApp gets completion, go to definition and error checking in VS Code. Keep writing the shared Kotlin code in Android Studio or IntelliJ IDEA.
Debug
Connect your iPhone over USB, select it in the KXBuild view and press F5. In both Swift and Kotlin you can set breakpoints, step through code and inspect variables. Kotlin objects expand by class and field.
Release
Build with the Release configuration to get an .ipa in the iosApp folder. To upload it to App Store Connect, see Release and App Store submission.
Use either of these
-
VS Code extension
Switch the configuration to Release in the Build configuration node of the KXBuild view, then run KXBuild: Build from the Command Palette.
-
Command line
> kxbuild build .\iosApp\iosApp.xcodeproj -c Release
Next steps
Build and configure
Debug versus Release, choosing a scheme, target and configuration, overriding build settings, where build products go, when you get an .ipa and when Swift package dependencies resolve.
Release and App Store submission
Build Release with a Distribution certificate to get an .ipa, upload it to App Store Connect with Transporter or Appuploader, then go through TestFlight and App Review. Ad Hoc and enterprise distribution work the same way.
Don't see your framework?
kxbuild is a general-purpose build toolchain, so if your framework produces an Xcode project, KXBuild can build it. The list above covers common cases only. Tell us about your setup.