Skip to content

Commit 0dac35b

Browse files
committed
Update
1 parent 5ba70f1 commit 0dac35b

File tree

7 files changed

+131
-281
lines changed

7 files changed

+131
-281
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: "Compose Multiplatform"
3+
description: "Learn how to integrate Sentry's Kotlin Multiplatform SDK into your Compose Multiplatform project for cross-platform error tracking."
4+
sdk: sentry.kotlin.multiplatform
5+
categories:
6+
- kotlin
7+
- multiplatform
8+
sidebar_order: 15
9+
---
10+
11+
# Compose Multiplatform
12+
13+
<Alert level="warning" title="Experimental Support">
14+
While Sentry's Kotlin Multiplatform SDK works in Compose Multiplatform projects, it isn't natively supported or fully tested for CMP. Some features may behave unexpectedly or provide incomplete data. Use with caution in production environments and report any issues you encounter.
15+
</Alert>
16+
17+
## Overview
18+
19+
**Compose Multiplatform** is JetBrains' declarative UI framework that allows you to build native user interfaces for desktop, web, and mobile platforms using a single Kotlin codebase. It extends Jetpack Compose beyond Android to create truly multiplatform applications.
20+
21+
It is required to use the [Sentry Kotlin Multiplatform SDK](/platforms/kotlin/guides/kotlin-multiplatform/) which provides error tracking across multiple Kotlin targets. While the SDK functions in Compose Multiplatform projects using the same APIs as pure KMP setups, it's important to note:
22+
23+
-**Experimental support**: The KMP SDK works in CMP projects and currently supports capturing crashes and errors as well as other basic features that are available through the Sentry KMP SDK.
24+
- ⚠️ **Not CMP-native**: No specific CMP optimizations or testing.
25+
- 🔍 **Untested edge cases**: Some platform-specific behaviors may be incomplete.
26+
27+
## Installation
28+
29+
Sentry captures data by using an SDK within your application's runtime.
30+
31+
<PlatformContent includePath="getting-started-install" />
32+
33+
## Configure
34+
35+
Configuration should happen as early as possible in your application's lifecycle.
36+
37+
<PlatformContent includePath="getting-started-config" />
38+
39+
## Verify
40+
41+
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.
42+
43+
<PlatformContent includePath="getting-started-verify" />
44+
45+
## Debug Symbols
46+
47+
Error stack traces in your app might appear unreadable or obfuscated, making it hard to debug issues. To make stack traces clear and human-readable in Sentry, you need to upload your app's debug symbols.
48+
49+
For step-by-step instructions, see the [Debug Symbols guide](/platforms/kotlin/guides/kotlin-multiplatform/debug-symbols/).

docs/platforms/kotlin/guides/kotlin-multiplatform/debug-symbols/index.mdx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,43 @@ For Apple applications please follow the iOS documentation on [Uploading Debug S
1515

1616
### Gradle
1717

18-
To upload ProGuard mapping files or Native debug symbols via Gradle you need to install the [Sentry Android Gradle](/platforms/android/configuration/gradle) plugin:
18+
To upload ProGuard mapping files or Native debug symbols via Gradle you need to install the [Sentry Android Gradle Plugin](/platforms/android/configuration/gradle) in your `androidApp` module:
1919

2020
```kotlin {filename:androidApp/build.gradle.kts}
2121
plugins {
2222
id("com.android.application")
2323
id("io.sentry.android.gradle") version "{{@inject packages.version('sentry.java.android.gradle-plugin', '3.0.0') }}"
2424
}
2525

26-
// Prevent Sentry dependencies from being included in the Android app through the AGP.
2726
sentry {
27+
// Prevent Sentry dependencies from being included in the Android app through the AGP.
2828
autoInstallation {
2929
enabled.set(false)
3030
}
31+
32+
// The slug of the Sentry organization to use for uploading proguard mappings/source contexts.
33+
org.set("___ORG_SLUG___")
34+
35+
// The slug of the Sentry project to use for uploading proguard mappings/source contexts.
36+
projectName.set("___PROJECT_SLUG___")
37+
38+
// The authentication token to use for uploading proguard mappings/source contexts.
39+
// WARNING: Do not expose this token in your build.gradle files, but rather set an environment
40+
// variable and read it into this property.
41+
authToken.set(System.getenv("SENTRY_AUTH_TOKEN"))
3142
}
3243
```
3344

45+
After installing the plugin, you need to configure your auth token as an environment variable:
46+
47+
<OrgAuthTokenNote />
48+
49+
```bash
50+
export SENTRY_AUTH_TOKEN=___ORG_AUTH_TOKEN___
51+
```
52+
53+
Once configured, the plugin will automatically upload the necessary debug symbols to Sentry when a release build is created.
54+
3455
#### ProGuard/R8 & DexGuard
3556

3657
Learn more in the Sentry Gradle Plugin docs for [ProGuard/R8 & DexGuard](/platforms/android/configuration/gradle/#proguardr8--dexguard).
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Initialize Sentry in your main application entry point, typically in your `main()` function or `App` composable:
2+
3+
```kotlin {filename:App.kt}
4+
import io.sentry.kotlin.multiplatform.Sentry
5+
import androidx.compose.runtime.Composable
6+
7+
@Composable
8+
fun App() {
9+
// Initialize Sentry when your app starts
10+
Sentry.init { options ->
11+
options.dsn = "___PUBLIC_DSN___"
12+
// Adds request headers and IP for users, for more info visit:
13+
// https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform/data-management/data-collected/
14+
options.sendDefaultPii = true
15+
}
16+
17+
// ... your compose UI content
18+
}
19+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
To install the Kotlin Multiplatform SDK in your Compose Multiplatform project, you need to add the following to your `build.gradle.kts` file in your shared module:
2+
3+
```kotlin {filename:composeApp/build.gradle.kts}
4+
plugins {
5+
id("io.sentry.kotlin.multiplatform.gradle") version "{{@inject packages.version('sentry.kotlin.kmp.gradle-plugin', '0.9.0') }}"
6+
}
7+
```
8+
9+
The plugin does the following:
10+
11+
- Automatically installs the Sentry KMP dependency to `commonMain`.
12+
- If you use the Kotlin Cocoapods plugin, it installs the Sentry Cocoa dependency.
13+
- If you use Swift Package Manager, it sets up linking to the Sentry Cocoa framework.
14+
15+
<Alert>
16+
17+
If you use Swift Package Manager instead of Cocoapods, you need to install the [sentry-cocoa dependency with Swift Package Manager](/platforms/apple/install/swift-package-manager/) in your Xcode project first before executing the Gradle plugin.
18+
19+
</Alert>

platform-includes/getting-started-install/kotlin.kotlin-multiplatform.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ To install the Kotlin Multiplatform SDK, you need to add the following to your `
22

33
```kotlin {filename:shared/build.gradle.kts}
44
plugins {
5-
id("io.sentry.kotlin.multiplatform.gradle") version "{{@inject packages.version('sentry.kotlin.kmp', '0.9.0') }}"
5+
id("io.sentry.kotlin.multiplatform.gradle") version "{{@inject packages.version('sentry.kotlin.kmp.gradle-plugin', '0.9.0') }}"
66
}
77
```
88

9-
The plugin installs the Sentry KMP dependency. If you're using the Cocoapods plugin, it will also install the Sentry Cocoa dependency.
9+
The plugin does the following:
10+
11+
- Automatically installs the Sentry KMP dependency to `commonMain`.
12+
- If you use the Kotlin Cocoapods plugin, it installs the Sentry Cocoa dependency.
13+
- If you use Swift Package Manager, it sets up linking to the Sentry Cocoa framework.
14+
1015

1116
<Alert>
1217

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
```kotlin
2+
import io.sentry.kotlin.multiplatform.Sentry
3+
4+
// Add the following button to your compose UI and click it to trigger an error
5+
Button(onClick = {
6+
try {
7+
throw Exception("Sentry works!")
8+
} catch (e: Exception) {
9+
Sentry.captureException(e)
10+
}
11+
}) {
12+
Text("Send an error to Sentry")
13+
}
14+
```

0 commit comments

Comments
 (0)