Home/Without a Mac/How do I build a Kotlin Multiplatform (or Compose Multiplatform) iOS app without a Mac?

How do I build a Kotlin Multiplatform (or Compose Multiplatform) iOS app without a Mac?

Updated · airankrush

The short answer

Short answer: you can write the shared Kotlin code on Windows or Linux and run the Android and desktop targets there. The official documentation states those hosts cannot build final binaries for Apple targets. The framework and the iosApp project have to be compiled on a Mac.

Which steps require macOS

What cannot leave macOS

  • Building the iOS framework. In Kotlin/Native's target support docs, the entry for Linux and Windows hosts says they can build final binaries for everything except Apple targets.
  • Building iosApp. It is an ordinary Xcode project that depends on the framework compiled from the shared module. In the docs' words: creating iOS apps requires a macOS machine with Xcode installed, and the IDE calls Xcode under the hood.

What you can do on Windows or Linux

  • Write the shared code in commonMain and run the Android and desktop targets. Compose Multiplatform UI can likewise be previewed on those two targets first.
  • Produce .klib files (an intermediate library artifact) for Apple targets, but the docs add a condition: when the project has cinterop dependencies (including CocoaPods), a macOS host is required. A .klib is not something you can install on a phone.

So the Mac's role is clear: link the shared module into a framework, then let Xcode package it into an app.

How to do it on a remote Mac

  1. Set up the environment on the remote Mac

    Install Xcode and launch it by hand once to finish initialization. The docs specifically remind you that after every Xcode update you need to open it by hand again so it downloads the updated tools. For the IDE, use IntelliJ IDEA or Android Studio and install the Kotlin Multiplatform plugin, which shows preflight warnings when Xcode is not set up properly.

  2. Understand the project structure

    In a wizard-generated project, iosApp is an Xcode project and the shared module is compiled into a framework for it to use. On the iOS side, the entry point of a Compose Multiplatform project is a function that returns a view controller:

    fun MainViewController() = ComposeUIViewController { App() }

    The iosApp, written in Swift, embeds it into the UI. The app name and Bundle ID can be changed without opening Xcode: edit APP_NAME and BUNDLE_ID in iosApp/Configuration/Config.xcconfig.

  3. Confirm how the framework is integrated

    Projects created with the IDE plugin use "direct integration" by default: Xcode's build phases contain a Run Script whose core is

    ./gradlew :shared:embedAndSignAppleFrameworkForXcode

    Replace the module name with your project's. This Gradle task puts the compiled framework in the right place and handles signing of the embedded framework. The docs list a few requirements:

    • The Run Script phase has to come before Compile Sources, with "Based on dependency analysis" unchecked.
    • Turn off User Script Sandboxing in Build Settings. If you built earlier with it on, run ./gradlew --stop first to stop the daemon.
    • This task is only registered when binaries.framework is declared in the Gradle script.

    Projects whose shared module pulls in CocoaPods dependencies need the CocoaPods plugin integration method instead. See the integration methods overview.

  4. Get it running in the simulator first

    In the IDE, choose the iosApp run configuration and a simulator, then click Run. The docs note that the first build collects native dependencies and builds up a cache, and later builds are faster. If it will not run, do not rush into archiving.

  5. Select the team in Xcode and archive

    Open the project from the IDE with "File | Open Project in Xcode". Select the iosApp target, choose your team in the Team list under Signing & Capabilities, and confirm the Bundle Identifier is unique and a signing certificate has been assigned. Then archive. During archiving, Xcode triggers the Gradle task above again and builds the Release framework.

    If the project uses custom build configurations other than Debug and Release, the docs require adding KOTLIN_FRAMEWORK_BUILD_TYPE under User-Defined in Build Settings, set to Debug or Release.

  6. Export or upload

    When archiving is done, distribute from the Organizer. For what follows, see signing a KMP app and uploading to TestFlight.

FAQ

The Xcode build reports that the Gradle script has no permission to access files

First check whether User Script Sandboxing is turned off. The docs explain that for a project built while sandboxing was on, you need ./gradlew --stop to stop the Gradle daemon that may already be sandboxed, then build again.

It runs fine from the IDE, but building from Xcode does not recompile the Kotlin code

This is the other side of intended behavior: when the IDE starts an iOS run configuration it builds the framework first and sets the environment variable OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED to YES, so the script in Xcode skips the duplicate build. When you build in Xcode on its own, the variable is absent and the script calls Gradle as normal.

What size of machine suits this kind of project?

Gradle, the Kotlin/Native compiler and Xcode use memory at the same time, so err on the generous side with specs. We have no measured data and give no specific figures. For available configurations and stock, see the plans page. If you are unsure, ask on Telegram at Contact support.

Can I skip the Mac and hand this to a cloud build?

Yes. Any cloud build service with macOS build machines can run the same Gradle plus Xcode flow, and JetBrains' docs also describe setting up a TeamCity Cloud pipeline from the IDE. For the trade-offs, see remote Mac vs cloud build.

Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support

Back to home · All no-Mac guides