# Kotlin Multiplatform | Sentry for Kotlin Multiplatform

Kotlin Multiplatform lets you write code once and use it on various platforms. It makes building apps easier and more efficient by sharing common code, while still benefitting from native capabilities.

Sentry's Kotlin Multiplatform SDK builds on top of multiple Sentry SDKs, allowing developers to share code between platforms while being able to integrate Sentry's features into their applications. Installing this SDK will enable native crash reporting and automatic breadcrumbs for app lifecycle and UI events.

## [Prerequisites](https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform.md#prerequisites)

Don't already have an account and Sentry project established? Head over to [sentry.io](https://sentry.io/signup/), then return to this page.

Xcode 16 support starts with Sentry Cocoa SDK version `8.36.0` or higher.

Starting May 1, 2024, Apple requires all apps submitted to the App Store to provide a list of privacy-related APIs they use. Use Sentry Cocoa SDK version `8.25.0` or higher to ensure compliance with these requirements. Follow our [Apple Privacy Manifest](https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform/data-management/apple-privacy-manifest.md) guide to learn more.

## [Install](https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform.md#install)

Sentry captures data by using an SDK within your application's runtime.

To install the Kotlin Multiplatform SDK, you need to add the following to your `build.gradle.kts` file in your shared module:

`shared/build.gradle.kts`

```kotlin
plugins {
  id("io.sentry.kotlin.multiplatform.gradle") version "0.19.0"
}
```

The plugin does the following:

* Automatically installs the Sentry KMP dependency to `commonMain`.
* If you use the Kotlin Cocoapods plugin, it installs the Sentry Cocoa dependency.
* If you use Swift Package Manager, it sets up linking to the Sentry Cocoa framework.

If you use Swift Package Manager instead of Cocoapods, you need to install the [Sentry Cocoa dependency with Swift Package Manager](https://docs.sentry.io/platforms/apple/install/swift-package-manager.md) in your Xcode project first before executing the Gradle plugin.

Make sure that you install the Sentry Cocoa SDK version compatible with the corresponding Sentry Kotlin Multiplatform SDK version. You can find the compatible versions in the [Sentry Kotlin Multiplatform SDK README](https://github.com/getsentry/sentry-kotlin-multiplatform?tab=readme-ov-file#cocoa-sdk-version-compatibility-table).

## [Configure](https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform.md#configure)

Configuration should happen as early as possible in your application's lifecycle.

`SentrySetup.kt`

```kotlin
import io.sentry.kotlin.multiplatform.Sentry

fun initializeSentry() {
  Sentry.init { options ->
    options.dsn = "https://examplePublicKey@o0.ingest.sentry.io/0"
    // Adds request headers and IP for users, for more info visit:
    // https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform/data-management/data-collected/
    options.sendDefaultPii = true
  }
}
```

## [Verify](https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform.md#verify)

This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.

```kotlin
import io.sentry.kotlin.multiplatform.Sentry

fun captureError() {
  try {
    throw Exception("This is a test.")
  } catch (e: Exception) {
    Sentry.captureException(e)
  }
}
```

Learn more about manually capturing an error or message in our [Usage documentation](https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform/usage.md).

To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.

## [Next Steps](https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform.md#next-steps)

* [Learn more about Sentry's Kotlin Multiplatform SDK features](https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform/features.md)
* [Learn about different ways to initialize the SDK](https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform/initialization-strategies.md)
* [See configuration options for the Kotlin Multiplatform Gradle Plugin](https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform/configuration/gradle.md)
* [Add readable stack traces to your errors](https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform/debug-symbols.md)
