
In endurance racing, every car on the grid carries a timing transponder. The circuit infrastructure picks it up at every sector boundary, at the finish line, in and out of the pit lane. You don’t have to ask whether a car is on the pace. The timing tower knows. The split is on the board before the marshal even looks up.
I thought about that when I tried to explain to a colleague why I cared so much about CI for a side project. “It’s a side project,” he said. “You know if it builds.” I do know if it builds, on my machine, for the one target I just tested, in the configuration I happen to be running today. That’s not the same as knowing the build is clean. And in a Kotlin Multiplatform project, the gap between “it works on my machine” and “it works” is wider than you’d think.
KMP gives you one codebase and two (or more) build targets. That’s the pitch. What the pitch leaves out is that Android and iOS builds have completely separate toolchains, separate runners, and separate failure modes. The shared module compiles fine for JVM and then refuses to link for the iOS simulator because you used a dependency that doesn’t support iosArm64. The Android unit tests pass and the commonTest suite throws a NullPointerException that only surfaces on the JVM. Both builds succeed locally because you only ran one of them.
CI is the timing transponder. It runs everything, every time, and puts the result on the board.
Why KMP CI is harder than Android CI
A pure Android project needs one runner, with Java and Gradle. Done. KMP adds a constraint that’s easy to miss until your first failed iOS pipeline. iOS builds require a macOS runner. You can’t compile an Xcode project or link an iOS framework on Linux. macOS runners on GitHub Actions cost roughly ten times more per minute than Ubuntu runners, so the naive “run everything on macOS” approach burns through your free tier fast.
The good news is that most of your KMP code, everything in commonMain, can be tested on the JVM. commonTest runs on jvmTest without a device, without a simulator, without Xcode. That means you can keep the expensive macOS runner focused on a single job, which is verifying that the Kotlin framework links and that the iOS app builds. Fast feedback on shared logic, expensive verification only where it counts.
The setup I’ve settled on for my own projects uses three jobs.
- common-tests runs
commonTeston Ubuntu with the JVM. It’s fast and cheap, and everything downstream waits for it. - android-build runs the Android build and Android unit tests on Ubuntu, after
common-tests. - ios-build links the KMP framework and builds the iOS app on macOS, after
common-tests.
The dependency structure means the JVM tests act as a gate. If shared logic breaks, you find out in two minutes on an Ubuntu runner, not ten minutes into the macOS job.
Setting up the workflow
Create .github/workflows/ci.yml at the root of your project. Here’s the full workflow.
# .github/workflows/ci.yml
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
common-tests:
name: Common Tests (JVM)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- uses: gradle/actions/setup-gradle@v4
with:
# only main writes the cache; PRs read it but never save it
cache-read-only: ${{ github.event_name == 'pull_request' }}
- name: Run commonTest on JVM
run: ./gradlew :shared:jvmTest
android-build:
name: Android Build + Unit Tests
runs-on: ubuntu-latest
needs: common-tests
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: ${{ github.event_name == 'pull_request' }}
- name: Assemble Android release APK
run: ./gradlew :androidApp:assembleRelease
- name: Run Android unit tests
run: ./gradlew :androidApp:testReleaseUnitTest :shared:testReleaseUnitTest
ios-build:
name: iOS Build
runs-on: macos-15
needs: common-tests
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: ${{ github.event_name == 'pull_request' }}
- name: Link KMP framework for iOS Simulator
run: ./gradlew :shared:linkDebugFrameworkIosSimulatorArm64
- name: Build iOS app (no signing)
run: |
xcodebuild build \
-scheme iosApp \
-destination 'generic/platform=iOS Simulator' \
-derivedDataPath build/DerivedData \
CODE_SIGNING_ALLOWED=NO
working-directory: iosApp
Three jobs, two runners, one gate. The needs: common-tests key on both android-build and ios-build means GitHub Actions won’t start either of those jobs until the JVM tests pass.
What commonTest on the JVM actually covers
The target jvmTest compiles your commonTest sources against the JVM implementation. That gives you full coroutines support, real collections, real time, and no runBlocking workarounds or fake dispatchers unless you want them. Any logic in commonMain that you’ve unit-tested is covered here.
But it doesn’t cover expect/actual implementations. The JVM test run uses jvmMain actuals, not the Android or iOS ones. If your actual implementations have platform-specific logic, like file paths, platform APIs or anything else that diverges between targets, those need to be tested on their own platforms.
For most projects, that’s fine. The majority of bugs in shared code are logic bugs, not platform-specific failures, and the JVM catches those. Platform-specific actuals usually wrap a system API that either works or doesn’t.
If you have a module that only targets Android and iOS (no
jvmMain), you won’t have ajvmTesttarget. In that case, runandroidUnitTeston the Ubuntu runner for your shared logic test pass. It’s not quite as fast, but it avoids the macOS runner for the bulk of your tests.
The Android job
The Android build step does two things, assembleRelease and testReleaseUnitTest. I run release instead of debug because the release configuration is what ships, and I’ve been burned enough times by ProGuard rules that only break in release to make it a habit.
The :shared:testReleaseUnitTest task in the same job catches the Android-specific actuals. If you have an actual implementation in androidMain that uses Context or an Android API, this is where it runs.
If you ever hit SDK location not found, the fix is a local.properties written from the runner’s SDK path, added before the Gradle steps.
# .github/workflows/ci.yml (android-build job, before Gradle steps)
- name: Write local.properties
run: echo "sdk.dir=$ANDROID_HOME" > local.properties
Most of the time you won’t need it, because the Android Gradle Plugin reads ANDROID_HOME on its own. It’s a fallback for builds that still read local.properties directly.
The iOS job, where linking is the real test
The iOS job does two things. First, linkDebugFrameworkIosSimulatorArm64 is the Gradle task that produces the .framework bundle your Xcode project consumes. If your commonMain has a dependency that doesn’t publish a iosSimulatorArm64 variant, or if your expect declarations don’t have matching actual implementations, this task fails. It’s the earliest point at which KMP-specific iOS problems surface.
Second, the xcodebuild call builds the actual iOS app. This catches Xcode-side issues like missing files, broken Swift code and misconfigured build phases. CODE_SIGNING_ALLOWED=NO skips code signing entirely. You’re not distributing from CI, you’re just verifying the build compiles and links.
It’s also worth knowing that I use generic/platform=iOS Simulator instead of naming a device. Runner images swap simulator runtimes and device models between releases, and a hardcoded name=iPhone 18 is exactly the kind of thing that breaks a green pipeline overnight. The goal is to verify the build compiles and links, not to pick a simulator.
Also note that if your Xcode project already runs embedAndSignAppleFrameworkForXcode in a build phase, xcodebuild triggers the Gradle link by itself. The explicit linkDebugFramework... step is redundant for correctness, but I keep it because when the framework fails to link, the error shows up in a plain Gradle log instead of buried in Xcode output.
Gradle caching makes it bearable
Without caching, a cold KMP build on GitHub Actions takes five to eight minutes on Ubuntu and twelve to fifteen minutes on macOS. With Gradle’s build cache and the gradle/actions/setup-gradle action, warm builds drop to two to three minutes on Ubuntu and five to six minutes on macOS.
The gradle/actions/setup-gradle@v4 action handles this automatically. It caches the Gradle wrapper, the dependency cache, and the build cache between runs. You don’t need to configure cache keys manually, since the action generates them from your Gradle files.
The cache-read-only: ${{ github.event_name == 'pull_request' }} line makes pull request runs restore the cache without saving a new one. The cache only gets written from main, so a half-finished PR can’t leave its own entries behind for other branches to pick up.
For push events on main, cache writes are enabled. That’s how the cache stays warm for the next PR.
Gotchas
1. The Xcode version on the runner changes without warning.
GitHub updates runner images, including Xcode, on their own schedule. A workflow that worked last month might break because the Xcode version changed and xcodebuild now behaves differently. Use a versioned label such as macos-15 or macos-26 instead of macos-latest, so the OS only changes when you change it. Even then, Xcode patch versions move inside an image. If you need an exact one, select it with sudo xcode-select -s /Applications/Xcode_26.5.app (the actions/runner-images repo lists what each image ships).
2. linkDebugFrameworkIosSimulatorArm64 vs. linkReleaseFramework.
On CI, linkDebug is fine. It skips optimizations and compiles faster. If you want to verify the release framework, for example to catch issues with @OptIn annotations or dead-code elimination, add a separate step.
- name: Link KMP release framework (optional)
run: ./gradlew :shared:linkReleaseFrameworkIosSimulatorArm64
I don’t run this on every PR because it’s slower and catches edge cases I’d rather catch in a dedicated release workflow. For the day-to-day CI gate, debug is enough.
3. The Android emulator is almost never worth it on CI.
Instrumented tests require a running Android emulator. Spinning one up on GitHub Actions adds five minutes to your job before a single test runs. Unless you have UI tests that can’t be run with Robolectric or Compose’s runComposeUiTest, I’d keep instrumented tests out of the default CI pipeline and run them on a schedule or before release. Unit tests and Robolectric cover the vast majority of business logic without the overhead.
4. The configuration cache is worth enabling, but verify it on CI.
The configuration cache speeds up repeated builds, but a custom Gradle task or an outdated third-party plugin can break it. Turn it on in gradle.properties and see whether CI stays green.
# gradle.properties
org.gradle.configuration-cache=true
If a task isn’t compatible, Gradle reports it in the build output. Fix or update the offending plugin, or mark that task as incompatible, rather than turning the cache off for the whole build.
Wrapping up
The three-job structure (JVM gate, Android build, iOS build) gives you fast feedback on logic bugs and platform-level verification without burning macOS runner minutes on tests that don’t need them. Gradle caching keeps warm builds fast enough that CI doesn’t feel like a tax. The timing transponder is on, and the board updates on every commit.
Set it up once and you stop thinking about it. That’s the point.
Every commit on the clock, every platform in the results. Keep it flat out. 🏁
The KMP Bits app is available on App Store and Google Play — built entirely with KMP.
Comments
Loading comments...