Skip to content

Commit 3b27776

Browse files
buenaflorgetsantry[bot]marandanetoshanamatthews
authored
feat(kmp): improve docs (#7024)
Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com> Co-authored-by: Manoel Aranda Neto <marandaneto@gmail.com> Co-authored-by: Shana Matthews <shana.l.matthews@gmail.com>
1 parent 4d4591b commit 3b27776

File tree

8 files changed

+308
-37
lines changed

8 files changed

+308
-37
lines changed

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

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
### Prerequisites (Android)
2-
3-
Android requires disabling auto-init to not clash with the ContentProvider, which auto-initializes the Sentry Android SDK. To do so, add the following to the AndroidManifest.xml file under your androidMain source set:
4-
5-
```xml
6-
<application>
7-
<meta-data android:name="io.sentry.auto-init" android:value="false" />
8-
</application>
9-
```
10-
111
To install the Kotlin Multiplatform SDK, you need to add the following to your `build.gradle.kts` file in your shared module:
122

133
```kotlin {filename:shared/build.gradle.kts}
@@ -16,20 +6,27 @@ repositories {
166
}
177

188
kotlin {
19-
val commonMain by getting {
20-
dependencies {
21-
api("io.sentry:sentry-kotlin-multiplatform:{{@inject packages.version('sentry.kotlin.kmp', '0.0.1-alpha.2') }}")
9+
android()
10+
iosX64()
11+
iosArm64()
12+
iosSimulatorArm64()
13+
14+
sourceSets {
15+
val commonMain by getting {
16+
dependencies {
17+
implementation("io.sentry:sentry-kotlin-multiplatform:{{@inject packages.version('sentry.kotlin.kmp', '0.0.1-alpha.2') }}")
18+
}
2219
}
23-
}
2420

25-
// Android target
26-
val androidMain by getting {
27-
dependsOn(commonMain)
28-
}
21+
// Android target
22+
val androidMain by getting {
23+
dependsOn(commonMain)
24+
}
2925

30-
// Apple targets:
31-
val iosMain by getting {
32-
dependsOn(commonMain)
26+
// Apple targets:
27+
val iosMain by getting {
28+
dependsOn(commonMain)
29+
}
3330
}
3431

3532
cocoapods {
@@ -41,7 +38,6 @@ kotlin {
4138

4239
framework {
4340
baseName = "shared"
44-
export("io.sentry:sentry-kotlin-multiplatform:{{@inject packages.version('sentry.kotlin.kmp', '0.0.1-alpha.2') }}")
4541
}
4642
}
4743
}

src/platform-includes/getting-started-primer/kotlin-multiplatform.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ Sentry's Kotlin Multiplatform SDK builds on top of multiple Sentry SDKs, allowin
88

99
<Note>
1010

11-
This SDK is currently experimental.
11+
Kotlin Multiplatform requires using version **8.4.0** of the Sentry Cocoa SDK, specifically. Other versions, including newer ones, aren't guaranteed to work.
1212

1313
</Note>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Cocoapods
3+
description: "Learn about installing the Sentry Kotlin Multiplatform SDK with Cocoapods."
4+
---
5+
6+
To install the Kotlin Multiplatform SDK and setup your Apple targets with Cocoapods, you need to add the following to your `build.gradle.kts` file in your shared module:
7+
8+
<Note>
9+
Kotlin Multiplatform requires using version **8.4.0** of the Sentry Cocoa SDK,
10+
specifically. Other versions, including newer ones, aren't guaranteed to work.
11+
</Note>
12+
13+
```kotlin {filename:shared/build.gradle.kts}
14+
repositories {
15+
mavenCentral()
16+
}
17+
18+
kotlin {
19+
iosX64()
20+
iosArm64()
21+
iosSimulatorArm64()
22+
23+
sourceSets {
24+
val commonMain by getting {
25+
dependencies {
26+
implementation("io.sentry:sentry-kotlin-multiplatform:{{@inject packages.version('sentry.kotlin.kmp', '0.0.1-alpha.2') }}")
27+
}
28+
}
29+
30+
// Other targets...
31+
32+
// Apple targets:
33+
val iosMain by getting {
34+
dependsOn(commonMain)
35+
}
36+
37+
cocoapods {
38+
summary = "Some description for the Shared Module"
39+
homepage = "Link to the Shared Module homepage"
40+
ios.deploymentTarget = "14.1"
41+
podfile = project.file("../iosApp/Podfile")
42+
pod("Sentry", "~> 8.4.0")
43+
44+
framework {
45+
baseName = "shared"
46+
}
47+
}
48+
}
49+
}
50+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Apple Installation Methods
3+
sidebar_order: 1
4+
description: "All the installation methods for the Apple platform."
5+
---
6+
7+
<PageGrid />
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: Swift Package Manager (SPM)
3+
description: "Learn about installing the Sentry Kotlin Multiplatform SDK with Swift Package Manager."
4+
---
5+
6+
<Note>
7+
Kotlin Multiplatform requires using version **8.4.0** of the Sentry Cocoa SDK,
8+
specifically. Other versions, including newer ones, aren't guaranteed to work.
9+
</Note>
10+
11+
Add the Sentry Cocoa SDK as a package in Xcode in your iOS app via **File > Add Packages**.
12+
Enter the Git repo URL in the search field:
13+
14+
```text
15+
https://github.com/getsentry/sentry-cocoa.git
16+
```
17+
18+
Define your dependency rule to have the exact version `8.4.0` and then click the "Add Package" button.
19+
20+
Alternatively, if your project uses a `Package.swift` file to manage dependencies, you can specify the target with:
21+
22+
```swift {tabTitle:Swift}
23+
.package(url: "https://github.com/getsentry/sentry-cocoa", from: "8.4.0"),
24+
```
25+
26+
Next, install the Kotlin Multiplatform SDK and setup your Apple targets by adding the following to your `build.gradle.kts` file in your shared module:
27+
28+
```kotlin {filename:shared/build.gradle.kts}
29+
repositories {
30+
mavenCentral()
31+
}
32+
33+
kotlin {
34+
listOf(
35+
iosX64(),
36+
iosArm64(),
37+
iosSimulatorArm64()
38+
).forEach {
39+
it.binaries.framework {
40+
baseName = "shared"
41+
isStatic = true // currently available only as static framework
42+
}
43+
}
44+
45+
sourceSets {
46+
val commonMain by getting {
47+
dependencies {
48+
implementation("io.sentry:sentry-kotlin-multiplatform:{{@inject packages.version('sentry.kotlin.kmp', '0.0.1-alpha.2') }}")
49+
}
50+
}
51+
52+
// Apple targets:
53+
val iosMain by getting {
54+
dependsOn(commonMain)
55+
}
56+
57+
// Other targets...
58+
}
59+
}
60+
```
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: Upload Debug Symbols
3+
sidebar_order: 1
4+
description: "Learn more about how to upload debug symbols in Sentry Kotlin Multiplatform."
5+
---
6+
7+
To symbolicate your stacktraces, you need to provide debug information to Sentry.
8+
The symbolication process unscrambles the stacktraces to reveal the function, file names, and line numbers of the crash.
9+
10+
## Apple
11+
12+
For Apple applications please follow the iOS documentation on [Uploading Debug Symbols](/platforms/apple/guides/ios/dsym) to set up debug symbols upload.
13+
14+
## Android
15+
16+
### Gradle
17+
18+
To upload ProGuard mapping files or Native debug bymbols via Gradle you need to install the [Sentry Android Gradle](/platforms/android/gradle) plugin:
19+
20+
```kotlin {filename:androidApp/build.gradle.kts}
21+
buildscript {
22+
repositories {
23+
mavenCentral()
24+
}
25+
}
26+
27+
plugins {
28+
id("com.android.application")
29+
id("io.sentry.android.gradle") version "{{@inject packages.version('sentry.java.android.gradle-plugin', '3.0.0') }}"
30+
}
31+
32+
// Prevent Sentry dependencies from being included in the Android app through the AGP.
33+
sentry {
34+
autoInstallation {
35+
enabled.set(false)
36+
}
37+
}
38+
```
39+
40+
#### ProGuard/R8 & DexGuard
41+
42+
Learn more in the Sentry Gradle Plugin docs for [ProGuard/R8 & DexGuard](/platforms/android/gradle/#proguardr8--dexguard).
43+
44+
#### Native Debug Symbols and Sources
45+
46+
You can find more information in the Sentry Gradle Plugin docs for [Native Debug Symbols and Sources](/platforms/android/gradle/#native-debug-symbols-and-sources).

src/platforms/kotlin-multiplatform/initialization-strategies.mdx

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Initialization Strategies
3-
sidebar_order: 0
3+
sidebar_order: 2
44
description: "Strategies for initializing the Kotlin Multiplatform SDK."
55
---
66

@@ -24,12 +24,17 @@ import io.sentry.kotlin.multiplatform.Sentry
2424

2525
// Application context is only needed for Android targets
2626
fun initializeSentry(context: Context?) {
27-
Sentry.init(context) {
28-
it.dsn = "___PUBLIC_DSN___"
27+
if (context != null) {
28+
Sentry.init(context) {
29+
it.dsn = "___PUBLIC_DSN___"
30+
// Add common configuration here
31+
}
2932
}
3033
}
3134
```
3235

36+
Now you can use that shared function to initialize the SDK.
37+
3338
### Android
3439

3540
```kotlin {filename:MainActivity.kt}
@@ -44,7 +49,7 @@ class YourApplication : Application() {
4449
}
4550
```
4651

47-
### Cocoa/Apple
52+
### iOS
4853

4954
```swift {filename:AppDelegate.swift}
5055
import shared
@@ -62,25 +67,63 @@ func application(
6267

6368
Platform-specific initializers allow for customization of the SDK's configuration options on a per-platform basis. This approach can be particularly useful when your SDK requires platform-specific functionality or performance optimizations.
6469

65-
With platform-specific initializers, you can initialize the SDK directly in the target platform's codebase. This approach gives you the flexibility to fine-tune the SDK's behavior to meet the unique needs of each platform.
70+
This approach gives you the flexibility to fine-tune the SDK's behavior to meet the unique needs of each platform.
71+
72+
### Common
73+
74+
```kotlin {filename:commonMain/AppSetup.kt}
75+
import io.sentry.kotlin.multiplatform.Context
76+
77+
expect fun initializeSentry(context: Context? = null)
78+
```
79+
80+
### androidMain
81+
82+
```kotlin {filename:androidMain/AppSetup.kt}
83+
import io.sentry.kotlin.multiplatform.Sentry
84+
import io.sentry.kotlin.multiplatform.Context
85+
86+
actual fun initializeSentry(context: Context?) {
87+
if (context != null) {
88+
Sentry.init(context) {
89+
it.dsn = "___PUBLIC_DSN___"
90+
// Add Android-specific configuration here
91+
}
92+
}
93+
}
94+
```
95+
96+
### iosMain
97+
98+
```kotlin {filename:iosMain/AppSetup.kt}
99+
import io.sentry.kotlin.multiplatform.Sentry
100+
import io.sentry.kotlin.multiplatform.Context
101+
102+
actual fun initializeSentry(context: Context?) {
103+
Sentry.init {
104+
it.dsn = "___PUBLIC_DSN___"
105+
// Add iOS-specific configuration here
106+
}
107+
}
108+
```
109+
110+
Now you can use that shared function to initialize the SDK.
66111

67112
### Android
68113

69114
```kotlin {filename:MainActivity.kt}
70-
import io.sentry.kotlin.multiplatform.Sentry
115+
import your.kmp.app.initializeSentry
71116

72117
class YourApplication : Application() {
73118
override fun onCreate() {
74119
super.onCreate()
75120
// Make sure to add the context!
76-
Sentry.init(this) {
77-
it.dsn = "___PUBLIC_DSN___"
78-
}
121+
initializeSentry(this)
79122
}
80123
}
81124
```
82125

83-
### Cocoa/Apple
126+
### iOS
84127

85128
```swift {filename:AppDelegate.swift}
86129
import shared
@@ -89,15 +132,13 @@ func application(
89132
_ application: UIApplication,
90133
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
91134
) -> Bool {
92-
Sentry.shared.doInit() { options in
93-
options.dsn = "___PUBLIC_DSN___"
94-
}
135+
AppSetupKt.initializeSentry(context = nil)
95136
return true
96137
}
97138
```
98139

99140
## Hybrid Approach
100141

101-
It's also possible to mix the two initialization strategies by creating custom `sourceSets` that only target specific platforms. This allows you to use a shared initializer for some platforms while utilizing platform-specific initializers for others.
142+
It's also possible to mix the two initialization strategies by creating [intermediate sourceSets](https://kotlinlang.org/docs/multiplatform-hierarchy.html) that only target specific platforms. This allows you to use a shared initializer for some platforms while utilizing platform-specific initializers for others.
102143

103144
For example, you may choose to use a shared initializer for Android and iOS platforms, while using a platform-specific initializer for the watchOS and tvOS platform. This approach provides a balance between consistency and customization.

0 commit comments

Comments
 (0)