Swift Package Manager (SPM)
Swift Package Manager is a powerful tool for managing dependencies in Swift that allows developers to enjoy a more native integration experience with Xcode. If you already use Swift Package Manager or prefer it over other package managers on Apple platforms, this guide will show you how to install the Kotlin Multiplatform SDK using Swift Package Manager.
Adding third party dependencies through Swift Package Manager in libraries such as the Sentry SDK is not yet officially supported in the Kotlin Multiplatform ecosystem and might not be compatible in more advanced use cases. We recommend installing our SDK with Cocoapods for the best compatibility and experience with Kotlin Multiplatform.
Ensure compatibility in Kotlin Multiplatform projects targeting Cocoa by using the version of the Cocoa SDK specified in our Cocoa SDK Version Compatibility Table.
Make sure your Kotlin Multiplatform framework is exported as a static framework by adding isStatic = true
Add the Sentry Cocoa SDK as a package in Xcode in your iOS app via File > Add Packages. Enter the Git repo URL in the search field:
https://github.com/getsentry/sentry-cocoa.git
Define your dependency rule to have the exact version 8.20.0
and then click the "Add Package" button.
Alternatively, if your project uses a Package.swift
file to manage dependencies, you can specify the target with:
.package(url: "https://github.com/getsentry/sentry-cocoa", from: "8.20.0"),
Next, install the Kotlin Multiplatform SDK and setup your Apple targets by adding the following to your build.gradle.kts
file in your shared module:
shared/build.gradle.kts
repositories {
mavenCentral()
}
kotlin {
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = "shared"
isStatic = true // currently available only as static framework
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("io.sentry:sentry-kotlin-multiplatform:0.5.0")
}
}
// Apple targets:
val iosMain by getting {
dependsOn(commonMain)
}
// Other targets...
}
}
If you configured the Sentry Kotlin Multiplatform SDK with Swift Package Manager and try running tests, it won't work out of the box and you'll encounter the following error: ld: framework 'Sentry' not found
.
Follow these steps for the workaround:
Choose the release based on the version specified in the version compatibility table, download the Sentry.xcframework.zip
, and unzip it.
Create a /Frameworks
directory in the directory where the test.kexe
resides. Put the Sentry.framework
into it. (The Sentry.framework
can be found inside of the ios-arm64_x86_64-simulator
.) The test.kexe
will usually reside in build/bin/iosSimulatorArm64/debugTest
.
shared/build.gradle.kts
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64(),
).forEach {
it.binaries.framework {
baseName = "shared"
isStatic = true
}
it.compilations.all {
if (compilationName == "test" && target.platformType == KotlinPlatformType.native) {
compilerOptions.configure {
freeCompilerArgs.add("-linker-options")
freeCompilerArgs.add("-F/your/path/Carthage/Build/Sentry.xcframework/ios-arm64_x86_64-simulator/")
}
}
}
}
Now your tests should run successfully.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
- Package:
- maven:io.sentry:sentry-kotlin-multiplatform
- Version:
- 0.5.0
- Repository:
- https://github.com/getsentry/sentry-kotlin-multiplatform