Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KMP: Add test section for SPM usage in KMP #9114

Merged
merged 7 commits into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion docs/platforms/kotlin-multiplatform/swift-package-manager.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ sidebar_order: 2

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.
However, we recommend [installing our SDK with Cocoapods](/platforms/kotlin-multiplatform/#install) because it currently has the best compatibility with Kotlin Multiplatform.

<Note>
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](/platforms/kotlin-multiplatform/#install) for the best compatibility and experience with Kotlin Multiplatform.
</Note>

## Prerequisites

Expand Down Expand Up @@ -68,3 +71,45 @@ kotlin {
}
}
```

## Running Tests

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:

### 1. Download the Sentry xcframework

Choose the release based on the version specified in the version compatibility table, download the `Sentry.xcframework.zip`, and unzip it.

### 2. Create Frameworks directory and insert Sentry.framework

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`.

### 3. Add the linker options

```kotlin {filename: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/")
}
}
}
}
```

### 4. Run the tests

Now your tests should run successfully.
Loading