Build Kotlin Multiplatform iOS Apps on Windows and Debug KMP
Gradle links the shared module. Compose Multiplatform and Tencent Kuikly build too.
Last updated
Build Kotlin Multiplatform iOS apps on Windows without changing your iosApp project or Gradle scripts: KXBuild handles the Kotlin/Native iOS linking, installs the app on your iPhone over USB, and lets you set breakpoints in both Swift and Kotlin and step from Swift into Kotlin. Compose Multiplatform projects work the same way, and a Release build writes an .ipa in the iosApp folder. Before you start, install JDK 17 or later and make sure the project root has gradlew.
How do I set up a Kotlin Multiplatform project on Windows?
1. Set up your environment
Install Android Studio as described in the Kotlin Multiplatform docs, then install the Kotlin Multiplatform plugin from its plugin marketplace.
2. Create a project
If you don't have a project yet, create one with the Kotlin Multiplatform wizard in Android Studio or on the JetBrains website and select the iOS target.
Open the project's root folder in VS Code with File > Open Folder…, or drag the folder into VS Code. This works the same for existing and new projects.
3. 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.
In the title bar of the KXBuild view, open the ··· menu and run Doctor (fix environment).
> kxbuild doctor D:\work\mykmpapp\iosApp\iosApp.xcodeprojHow do I debug KMP Swift and Kotlin code on an iPhone?
4. 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.
5. Debug
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. Kotlin expression evaluation isn't supported, so assign a value to a local variable first if you need to inspect it.
Run the command below to build the app, install it on your iPhone and launch it.
> kxbuild run .\iosApp\iosApp.xcodeprojBefore you connect a phone for the first time, install and open Apple Devices from the Microsoft Store to get the USB driver on Windows. On iOS 16 and later, turn on Developer Mode in Settings > Privacy & Security and let the phone restart. See connect an iPhone to Windows for the full steps.
How do I build a Kotlin Multiplatform iOS app as an .ipa?
6. Release
Build with the Release configuration to get an .ipa in the iosApp folder. To upload it to App Store Connect, see publish to the App Store from Windows.
Run KXBuild: Build for App Store (.ipa) from the Command Palette or the project's context menu.
> kxbuild build .\iosApp\iosApp.xcodeproj -c Release --export app-storeAn App Store .ipa must be signed with an Apple Distribution certificate. Put your own .p12 certificate and .mobileprovision profile in a keychain/ folder and every build signs automatically; see sign iOS apps on Windows. Upload with kxstore (kxstore build upload, on Windows, Linux or macOS), then handle TestFlight and review on App Store Connect. That way you build Kotlin Multiplatform iOS apps on Windows, debug them on a real iPhone and upload them from one computer, while Android keeps building in Android Studio.
How do I build a Tencent Kuikly project for iOS on Windows?
Kuikly is built on Kotlin Multiplatform. Its iOS host project pulls in the shared module with CocoaPods, and Gradle builds the Kotlin/Native framework during the build, so KXBuild builds, installs and packages it as usual. Compared with the steps above there are two extra steps: generate the shared module's placeholder framework, then run pod install in iosApp and build iosApp.xcworkspace. demo below is the shared module's name in Kuikly's official KuiklyUI repository; use your project's module name.
> gradlew.bat :demo:generateDummyFrameworkiosApp> pod install> kxbuild doctor .\iosApp\iosApp.xcworkspaceKuiklyUI uses Gradle 7.6, which supports JDK 19 at most. If your computer has a newer JDK, install JDK 17 as well and point JAVA_HOME at it. Recent iOS SDKs require a deployment target of 15.0 or later, and Kuikly's Podfile treats the renderer's warnings as errors. If the build fails with "The selected platform is no longer supported by libc++", add these lines to the Podfile's existing post_install block, under installer.pods_project.targets.each do |target|, then run pod install again:
target.build_configurations.each do |config|
if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 15.0
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.0'
end
flags = ' -Wno-error=deprecated-declarations -Wno-error=deprecated-implementations -Wno-error=#warnings -Wno-error=unguarded-availability-new'
config.build_settings['OTHER_CFLAGS'] = '$(inherited)' + flags
endNext 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 kxstore (or Transporter on a Mac), 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.