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 3 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
48 changes: 47 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>
Swift Package Manager 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,46 @@ kotlin {
}
}
```

## Running Tests

If you configured the Sentry Kotlin Multiplatform SDK with Swift Package Manager, running tests will not work out of the box.
You are going to encounter the following error `ld: framework 'Sentry' not found`.

Follow these steps in order to work around this issue:
buenaflor marked this conversation as resolved.
Show resolved Hide resolved

### 1. Download the Sentry xcframework

Choose the release based on the version specified in the version compatibility table and download the `Sentry.xcframework.zip` and unzip it.
buenaflor marked this conversation as resolved.
Show resolved Hide resolved

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

Create a `/Frameworks` directory in the directory where the `test.kexe` resides in and put the `Sentry.framework` into it (`Sentry.framework` can be found inside of `ios-arm64_x86_64-simulator`).
The `test.kexe` will usually reside in `build/bin/iosSimulatorArm64/debugTest`.
buenaflor marked this conversation as resolved.
Show resolved Hide resolved

### 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