CoursesKotlin Multiplatform, from the compiler up
Puzzle 28 · 29 of 32
What has to match
Puzzle 27's Run Script works on your Mac. Then the build server, a Linux machine, can't make the framework; an iOS colleague updates Xcode and the Kotlin build breaks; and the app wants to run on an older iPhone than your framework. Here are the three things that must match, and where each is written down.
All puzzles in this course
The problem
Puzzle 27's Run Script builds your framework on your Mac, every time Xcode builds. Then three things go wrong in one month. The team's build server, a Linux machine, runs the release task from puzzle 26 and fails. An iOS colleague installs the newest Xcode, and the Kotlin build starts failing on their Mac only. And the product team wants the app to keep running on iPhones with an older iOS than your framework was built for. None of this is about your Kotlin code. What has to match?
See it
Scroll sideways to see the full diagram.
The build host is the machine that runs the build. A Linux host can compile your shared code into klibs for iOS. Predict: can it link the framework?
Step 1 of 5No: Kotlin builds final binaries for Apple targets only on a Mac. A Mac host makes both.
Step 2 of 5Each Kotlin version names the newest Xcode it was tested with, in Kotlin's compatibility guide. Move the two together.
Step 3 of 5The app's deployment target is the oldest iOS it supports. Kotlin's framework supports iOS 15.0 and later. Predict: does an iOS 14.0 app match?
Step 4 of 5No: the app would promise to run where its framework wasn't built for. Raise the app to 15.0, or lower Kotlin's minimum on purpose.
Step 5 of 5
The building block
The first thing is the machine that runs the build, the build host. Kotlin's docs list which hosts can build what, and for Apple targets the split is exactly puzzle 23's two stages:
| Build host | Final binaries (the link stage) | klibs (the compile stage) |
|---|---|---|
| a Mac, Apple chip or Intel | any supported target | any supported target |
| Linux or Windows | any target except Apple's | Apple targets too, unless the project makes its own bindings to C or Objective-C code (like puzzle 2's platform libraries, but for your own libraries) |
The docs say it plainly: "Building final binaries for Apple targets on Linux and Windows is also not possible." So a build server can check and compile your shared code for iOS on Linux, but the job that links the framework or the XCFramework, and every iOS test run, needs a Mac.
The second thing is Xcode's version. Kotlin's docs say that "to compile Apple targets, you need to install Xcode and its command-line tools": the Kotlin build itself uses tools that come with Xcode. So each Kotlin version names the newest Xcode it was tested with. Kotlin's compatibility guide keeps the table; two rows of it:
| Kotlin | Newest Xcode it's tested with |
|---|---|
| 2.4.20–2.4.21 | 26.4 |
| 2.3.20–2.3.21 | 26.0 |
So when the iOS team moves to a new Xcode, check the table and move Kotlin with it; and when you upgrade Kotlin, check which Xcode it expects. With a newer Xcode than its row, the Kotlin Gradle plugin warns: "Stability in such configuration hasn't been tested". The build may still work, or may break, as it did for your colleague. Kotlin even removes targets to keep up: it deprecated one 32-bit watch target "to ensure compatibility with Xcode 27".
The third thing is the oldest iOS version. An iOS app has a deployment target: in Apple's words, "your app's minimum deployment target defines the range of operating system versions your app supports". Your Kotlin framework has a minimum of its own: by default, Kotlin builds Apple targets for iOS 15.0 and later. The app can't promise to run where its framework wasn't built to run, so keep the app's deployment target at 15.0 or higher. If the app really must support an older iOS, lower Kotlin's minimum on purpose, with a line Kotlin's docs give:
freeCompilerArgs += "-Xoverride-konan-properties=minVersion.ios=14.0"
The analogy
The print shop from puzzle 23 only owns the presses for Apple's paper in one city, so the final print run happens there, though manuscripts can be typeset anywhere. Its presses are certified for one model of stitching machine at a time: when the restaurant's supplier changes the model, the shop upgrades too. And a cookbook printed for kitchens built after 2021 can't be promised to a restaurant whose oldest kitchen is from 2020, unless the shop prints a special edition.
Check yourself
Sources
- Kotlin Gradle plugin source: KotlinToolingDiagnostics.kt ("Stability in such configuration hasn't been tested")
- Kotlin docs: Kotlin/Native target support (hosts table: "macOS on Apple silicon (ARM64) Any supported target Any supported target"; "Linux with x86_64 architecture Any supported target, except for Apple targets Any supported target, Apple targets only without cinterop dependencies"; "Building final binaries for Apple targets on Linux and Windows is also not possible."; "Currently, the default minimum supported versions of Apple targets are: For iOS and tvOS, 15.0.";
freeCompilerArgs += "-Xoverride-konan-properties=minVersion.ios=14.0"; "For example, you can run macosArm64 and iosArm64 tests only on the macOS ARM64 host") - Kotlin docs: Compatibility guide for Kotlin Multiplatform ("check the compatibility of a particular version of the Kotlin Multiplatform Gradle plugin (same as the Kotlin version in your project) with Gradle, Xcode, and Android Gradle plugin versions"; table rows "2.4.20–2.4.21 7.6.3–9.7.0 8.5.2–9.3.1 26.4" and "2.3.20–2.3.21 7.6.3–9.3.0 8.2.2–9.0.0 26.0")
- Kotlin docs: What's new in Kotlin 2.4.20 ("the watchosArm32 Kotlin/Native target is now deprecated. It's planned for removal in Kotlin 2.5.0 to ensure compatibility with Xcode 27")
- Kotlin docs: Kotlin/Native overview ("To compile Apple targets, you need to install Xcode and its command-line tools.")
- Apple: Running code on a specific platform or OS version ("Your app's minimum deployment target defines the range of operating system versions your app supports.")
What you now know
Kotlin/Native builds final binaries for Apple targets only on a Mac; Linux and Windows can still produce klibs. Each Kotlin version lists the newest Xcode it was tested with in Kotlin's compatibility table, so upgrade the two together. And a Kotlin framework supports iOS 15.0 and later by default, so the app's deployment target must be at least that, or you lower Kotlin's minimum on purpose.
Answer every question above correctly to unlock the next puzzle.
Something wrong or unclear on this page? Tell me: a puzzle that didn't click is a bug in the puzzle.