You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Platform specific initializers](#platform-specific-initializers)
11
12
-[Hybrid approach](#hybrid-approach)
12
13
13
-
## Shared Initializer
14
-
15
-
The shared initializer approach involves initializing the SDK in your shared codebase, using the same configuration options for all platforms. This approach is ideal for projects that prioritize consistency across platforms and do not require platform-specific customizations.
14
+
## Where to Place Initialization Code
16
15
17
-
Using a shared initializer provides a single source of truth for your SDK's configuration options. This can simplify maintenance and debugging efforts, as you only need to update one codebase for all platforms.
18
-
19
-
To initialize the SDK, create a Kotlin file in your `commonMain` e.g. `AppSetup.kt`, (or whatever you decide to call it), and create an initialization function. You'll then be able to call it in an early lifecycle stage in your platforms.
20
-
21
-
<SignInNote />
22
-
23
-
```kotlin {filename:AppSetup.kt}
24
-
importio.sentry.kotlin.multiplatform.Sentry
25
-
26
-
// Application context is only needed for Android targets
27
-
funinitializeSentry() {
28
-
val configuration: (SentryOptions) ->Unit= {
29
-
it.dsn ="___PUBLIC_DSN___"
30
-
// Add common configuration here
31
-
}
32
-
Sentry.init(configuration)
33
-
}
34
-
```
35
-
36
-
Now you can use that shared function to initialize the SDK.
16
+
Regardless of the initialization strategy you choose, it's important to place the initialization code at an early lifecycle stage of your application to ensure the SDK is set up correctly before it is used.
17
+
Here are general guidelines for placing the initialization code for different platforms:
37
18
38
19
### Android
39
20
@@ -62,11 +43,89 @@ func application(
62
43
}
63
44
```
64
45
46
+
## Native Platform Options
47
+
48
+
<Note>
49
+
Requires Sentry SDK version `0.7.1` or higher.
50
+
</Note>
51
+
52
+
This approach involves initializing the SDK with the platform's specific options directly, using `PlatformOptionsConfiguration`. This strategy is ideal for projects that require configuring options that are not yet supported by the KMP SDK, such as experimental options.
53
+
For example, if you configure your KMP application for Android, you will have access to every option that the Android SDK provides.
54
+
55
+
### Apple Target Requirements
56
+
57
+
In order to be able to use the native platform options with Apple targets, you need to opt-in to `ExperimentalForeignApi`.
The shared initializer approach involves initializing the SDK in your shared codebase, using the same configuration options for all platforms. This approach is ideal for projects that prioritize consistency across platforms and do not require platform-specific customizations.
102
+
103
+
Using a shared initializer provides a single source of truth for your SDK's configuration options. This can simplify maintenance and debugging efforts, as you only need to update one codebase for all platforms.
104
+
105
+
To initialize the SDK, create a Kotlin file in your `commonMain` (such as `AppSetup.kt` or whatever you decide to call it), and write an initialization function. You'll then be able to call it in an early lifecycle stage in your platforms.
106
+
107
+
<SignInNote />
108
+
109
+
```kotlin {filename:AppSetup.kt}
110
+
importio.sentry.kotlin.multiplatform.Sentry
111
+
112
+
// Application context is only needed for Android targets
113
+
funinitializeSentry() {
114
+
val configuration: (SentryOptions) ->Unit= {
115
+
it.dsn ="___PUBLIC_DSN___"
116
+
// Add common configuration here
117
+
}
118
+
Sentry.init(configuration)
119
+
}
120
+
```
121
+
65
122
## Platform-Specific Initializers
66
123
67
124
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.
68
125
69
126
This approach gives you the flexibility to fine-tune the SDK's behavior to meet the unique needs of each platform.
127
+
However, the available options are limited to what the KMP SDK has implemented.
128
+
If you need to use the respective platform's options directly, you should use the [native platform options](#native-platform-options) approach.
70
129
71
130
### Common
72
131
@@ -108,37 +167,8 @@ actual fun initializeSentry() {
108
167
}
109
168
```
110
169
111
-
Now you can use that shared function to initialize the SDK.
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.
172
+
It's also possible to mix the initialization strategies by creating [intermediate sourceSets](https://kotlinlang.org/docs/multiplatform-hierarchy.html) that target specific platforms. This allows you to use a shared initializer for some platforms, while utilizing platform-specific initializers for others.
143
173
144
-
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.
174
+
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 platforms. This approach provides a balance between consistency and customization.
Copy file name to clipboardExpand all lines: platform-includes/getting-started-primer/kotlin-multiplatform.mdx
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -18,9 +18,9 @@ Use the Kotlin Multiplatform and Cocoa SDK combinations listed in the table belo
18
18
| Up to 0.3.0 | 8.4.0 |
19
19
| 0.4.0 | 8.17.2 |
20
20
| 0.5.0 | 8.21.0 |
21
-
| 0.6.0 |8.25.0 |
21
+
|>= 0.6.0 |~> 8.25 |
22
22
23
23
<Note>
24
-
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` to ensure compliance with these requirements.
24
+
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.
25
25
Follow our [Apple Privacy Manifest](/platforms/kotlin-multiplatform/data-management/apple-privacy-manifest) guide to learn more.
0 commit comments