Skip to content

Commit

Permalink
KMP: Add test section for SPM usage in KMP (#9114)
Browse files Browse the repository at this point in the history
* commit

* update

* update

* Update docs/platforms/kotlin-multiplatform/swift-package-manager.mdx

Co-authored-by: Liza Mock <[email protected]>

* Update docs/platforms/kotlin-multiplatform/swift-package-manager.mdx

Co-authored-by: Liza Mock <[email protected]>

* Update docs/platforms/kotlin-multiplatform/swift-package-manager.mdx

Co-authored-by: Liza Mock <[email protected]>

* Update swift-package-manager.mdx

---------

Co-authored-by: Liza Mock <[email protected]>
  • Loading branch information
buenaflor and lizokm authored Feb 16, 2024
1 parent e8216b0 commit 909551a
Showing 1 changed file with 46 additions and 1 deletion.
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.

0 comments on commit 909551a

Please sign in to comment.