Skip to content

Commit 724817a

Browse files
buenaflorcursoragentcoolguyzone
authored
feat(kmp): add Compose Multiplatform guide & clean up (#14392)
Adds a guide for `Compose Multiplatform` and cleans up some docs around KMP --------- Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: Alex Krawiec <[email protected]>
1 parent 571d9d1 commit 724817a

File tree

6 files changed

+164
-4
lines changed

6 files changed

+164
-4
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 (CMP) 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 multiplatform applications.
20+
21+
You need 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 use the same APIs as pure KMP setups, it's important to note a few differences:
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 to ensure a working instrumentation. Configure with the following steps:
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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
1. Add a function to initialize Sentry to your shared module (`commonMain`).
2+
2. Call the function in your iOS and Android app modules.
3+
4+
```kotlin {filename:SentrySetup.kt}{tabTitle: commonMain}
5+
import io.sentry.kotlin.multiplatform.Sentry
6+
7+
fun initializeSentry() {
8+
Sentry.init { options ->
9+
options.dsn = "___PUBLIC_DSN___"
10+
// Adds request headers and IP for users, for more info visit:
11+
// https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform/data-management/data-collected/
12+
options.sendDefaultPii = true
13+
}
14+
}
15+
```
16+
```swift {tabTitle: iosApp}
17+
import ComposeApp // Replace this with the name of the shared framework
18+
19+
@main
20+
struct iOSApp: App {
21+
init() {
22+
SentrySetupKt.initializeSentry()
23+
}
24+
var body: some Scene {
25+
WindowGroup {
26+
ContentView()
27+
}
28+
}
29+
}
30+
31+
// OR alternatively in AppDelegate:
32+
33+
34+
func application(
35+
_ application: UIApplication,
36+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
37+
) -> Bool {
38+
SentrySetupKt.initializeSentry()
39+
return true
40+
}
41+
42+
```
43+
```kotlin {filename:MainActivity.kt}{tabTitle: androidApp}
44+
import your.kmp.app.initializeSentry
45+
46+
class YourApplication : Application() {
47+
override fun onCreate() {
48+
super.onCreate()
49+
initializeSentry()
50+
}
51+
}
52+
```
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 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)