KMMBridge Documentation
repository·main·Indexed 19 days ago
https://github.com/touchlab/kmmbridgeKMMBridge provides Gradle-based tooling to automate the publishing and consumption of pre-built Kotlin Multiplatform (KMP) Xcode Framework binaries. It streamlines the integration of KMP code into iOS projects by managing the distribution of compiled frameworks via Swift Package Manager (SPM) and CocoaPods, including automated GitHub deploy key setup and podspec generation.
What's inside KMMBridge
- KMMBridge is a set of Gradle tooling designed to facilitate the publishing and consuming of pre-built Kotlin Multiplatform (KMP) Xcode Framework binaries. It helps bridge the gap between Kotlin Multiplatform development and iOS/Xcode integration by managing the distribution of compiled frameworks.
How KMMBridge project tests work
mainKMMBridge tests do not use Gradle include builds. Instead, they follow this lifecycle:
- A temporary folder is created.
- A sample app project (located in
test-projects/basic) is copied into that temporary folder. - A command-line process (typically a Gradle command) is executed within that folder to verify the plugin's behavior.
The test project at
test-projects/basicis pre-configured to point to the local KMMBridge version9.9.9.Use the KMMBridge v1 SPM Template
mainThis template project is designed for Kotlin Multiplatform (KMP) developers who want to use KMMBridge to publish Xcode Framework binaries via Swift Package Manager (SPM). It serves as a starting point for setting up the necessary infrastructure to bridge KMP code to iOS using the KMMBridge v1 workflow.Publish KMMBridge locally for testing
mainTo test KMMBridge against external projects, you must first publish it to your local Maven repository using a specific fake version (
9.9.9). This allows test projects to reference a local instance of the plugin without needing to use Gradle include builds, which avoids JVM classpath conflicts.Run this command from the root folder of the KMMBridge repository:
./gradlew publishToMavenLocal -PVERSION_NAME=9.9.9Configure CocoaPods Spec Repository Type
mainWhen using the
CocoapodsDependencyManager, you must specify whether you are pushing to the public CocoaPods Trunk or a private repository. This determines whichpodcommand is executed during thepushRemotePodspectask.- Trunk: For public distribution via
pod trunk push. - Private: For internal/private distribution via
pod repo push <specUrl>.
- Trunk: For public distribution via
Push Podspecs to CocoaPods via KMMBridge
mainKMMBridge provides Gradle tasks to automatically generate and push
.podspecfiles to either the CocoaPods Trunk or a private Spec repository. This allows your KMM library to be consumed as a CocoaPods dependency.Available Tasks
generateReleasePodspec: Generates a.podspecfile based on your Kotlin CocoaPods configuration and the deployment URL provided by KMMBridge.pushRemotePodspec: Triggers the generation and then pushes the podspec to the configured repository.
Repository Types
- Trunk: Uses
pod trunk pushto upload to the public CocoaPods repository. - Private: Uses
pod repo push <specUrl> <podSpecFile>to upload to a custom, private specification repository.
Configuration Behavior
The generated podspec includes:
- The deployment URL (from KMMBridge's URL file).
- Versioning derived from your project or KMMBridge settings.
- Platform deployment targets (iOS, OSX, tvos, watchos).
- Dependencies defined in your Kotlin CocoaPods block.
- Custom spec attributes defined via
extraSpecAttributes. - Automatic inclusion of
vendored_frameworks(the.xcframework) andlibraries = 'c++'unless explicitly overridden in your configuration.
# Example usage in a terminal (assuming tasks are registered) ./gradlew pushRemotePodspec # The task will: # 1. Generate the podspec in build/kmmbridge/podspec/ # 2. Execute 'pod trunk push' or 'pod repo push' depending on your setup.Implement a sample KMMBridge test
mainTests are implemented by running shell commands against a test project directory. You can use
ProcessHelper.runShto execute Gradle tasks and verify the exit status. Thesetup()function inco.touchlab.kmmbridge.SimplePluginTesthandles the initialization and copying of the test project.@Test fun runSpmDevBuild() { val result = ProcessHelper.runSh("./gradlew spmDevBuild --stacktrace", workingDir = testProjectDir) logExecResult(result) assertEquals(0, result.status) }Configure GitHub deployment repositories
mainTo use the GitHub integration features of KMMBridge, you must provide the source and target repository names. These are used to set up SSH deploy keys for automated publishing workflows.
Required properties:
githubDeploySourceRepo: The name of the GitHub repository where the SSH private key will be stored as a secret.githubDeployTargetRepo: The name of the GitHub repository where the SSH public deploy key will be added.
Setup GitHub deploy keys with setupDeployKeys
mainThe
setupDeployKeystask is a helper task that automates the creation of SSH deploy keys for GitHub. It performs the following steps:- Generates an
ed25519SSH key pair in a temporary directory. - Uses the GitHub CLI (
gh) to add the public key as a deploy key to thegithubDeployTargetRepo. - Uses the GitHub CLI (
gh) to set the private key as a repository secret in thegithubDeploySourceRepo.
Requirements:
- The
gh(GitHub CLI) must be installed and authenticated on the machine running the task. githubDeploySourceRepoandgithubDeployTargetRepomust be configured in your Gradle project.
Optional Configuration:
githubDeployKeyPrefix: A prefix used for the secret name and the deploy key label. Defaults toKMMBridge.
./gradlew setupDeployKeys- Generates an