KMMBridge - XCFramework publishing for Kotlin Multiplatform
KMMBridge is a Gradle plugin that allows you to publish Xcode XCFrameworks from your Kotlin Multiplatform projects. Developers using Xcode can then directly consume these XCFrameworks using Swift Package Manager (SPM) or CocoaPods.
KMMBridge can be used to publish your iOS KMP builds to public or private repos, using various backend options to host the binary XCFramework files.
Quick Start
Configuring any production publication from scratch can be difficult. However, if you are using GitHub and looking to publish only for SPM, we have a quick-start option that will get you up and running in minutes.
We also have a quick-start option for publishing with CocoaPods.
If you are upgrading from KMMBridge 1.0, you likely do not have much to do, but there might be minimal changes necessary. See Upgrading from KMMBridge 1.0.
Publishing Overview
To make Kotlin code available to Xcode and/or Swift build targets, the Kotlin KMP compiler builds an Xcode Framework. Regardless of the method by which you include that Framework, that is how Kotlin code is made available to Xcode.
All out-of-the-box build configurations for KMP are locally integrated. That means, to call KMP from Xcode, you need to locally build your Kotlin code.
However, you can assemble and publish these same builds for others to use directly. That is what KMMBrdige does. The broad steps are:
- In CI, the Kotlin compiler builds an Xcode Framework from KMP source
- The Framework outputs are converted to XCFramework packages, then all architectures are zipped into one file
- The binary file is uploaded to some cloud host (GitHub Packages/Releases, AWS S3, Maven Repo, etc)
- The Package.swift file is updated in the KMP repo
- Xcode accesses the Kotlin build through SPM. It gets the
Package.swift
file from git, and the Kotlin XCFramework from the cloud host
Publishing for CocoaPods is possible with KMMBridge as well. The binary XCFramework is published in the same way. In fact, if you publish both SPM and CocoaPods, they’ll both use the same published binary. CocoaPods needs to publish its package metadata, a “podspec” file, to a separate repo whose only purpose is to host podspec files.
KMMBridge Setup Overview
To use KMMBridge, you’ll need the following:
- A KMP module configured to build some Xcode Frameworks that you want to publish (this is in your Gradle config).
- A
DependencyManager
implementation and it’s related configuration. The options are SPM and CocoaPods. You can use both at the same time if publishing to both. - An
ArtifactManager
. This interface actually “publishes” the zip file to a remote server, and generates the url from which your published binary can be accessed. - Build and publication process. Generally a CI workflow. This is also your code. Our tutorials provide examples focused on GitHub Actions, but CI integration with production systems is often custom.
- Xcode config to access both the dependency config file and the zip file.
Xcode access to dependencies can be confusing and is often a source of issues. Please make sure to pay particular attention to the instructions and possible error conditions.
Specifically, for private repos and private XCFramework.zip binary storage, access must be configured separately for both. This is often a source of confusion and errors.
Swift Package Manager (SPM)
CocoaPods
Binary Artifacts
When publishing XCFrameworks, the Kotlin compiler creates a Framework for each target architecture. Each Framework is then converted to an XCFramework. All of these are then bundled into a single zip file.
That zip file needs to be hosted somewhere that is accessible by a stable URL.
Options provided by KMMBridge:
- GitHub Releases
- Maven repos (including GitHub Packages)
- Amazon S3 (only for public URLs without authentication)
You can implement a custom artifact location by implementing ArtifactManager
.
Reach Out
For help, discussions, issues, etc, Reach Out