File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed
sentry-kotlin-multiplatform/src
androidMain/kotlin/io/sentry/kotlin/multiplatform
androidUnitTest/kotlin/io/sentry/kotlin/multiplatform Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ pod("Sentry") {
14
14
}
15
15
```
16
16
17
+ ### Fixes
18
+
19
+ - Don't crash app when ` applicationContext ` is not available ([ #217 ] ( https://github.com/getsentry/sentry-kotlin-multiplatform/pull/217 ) )
20
+
17
21
### Enhancements
18
22
19
23
- Make ` setSentryUnhandledExceptionHook ` public ([ #208 ] ( https://github.com/getsentry/sentry-kotlin-multiplatform/pull/208 ) )
Original file line number Diff line number Diff line change @@ -11,10 +11,18 @@ import io.sentry.kotlin.multiplatform.extensions.toAndroidSentryOptionsCallback
11
11
internal actual fun initSentry (configuration : OptionsConfiguration ) {
12
12
val options = SentryOptions ()
13
13
configuration.invoke(options)
14
- SentryAndroid .init (applicationContext, options.toAndroidSentryOptionsCallback())
14
+
15
+ val context = applicationContext ? : run {
16
+ // TODO: add logging later
17
+ return
18
+ }
19
+
20
+ SentryAndroid .init (context) { sentryOptions ->
21
+ options.toAndroidSentryOptionsCallback().invoke(sentryOptions)
22
+ }
15
23
}
16
24
17
- internal lateinit var applicationContext: Context
25
+ internal var applicationContext: Context ? = null
18
26
private set
19
27
20
28
public actual typealias Context = Context
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import org.junit.Before
7
7
import org.junit.Test
8
8
import org.junit.runner.RunWith
9
9
import org.mockito.Mockito.mock
10
+ import kotlin.test.assertNotNull
10
11
11
12
@RunWith(AndroidJUnit4 ::class )
12
13
class SentryContextProviderTest : BaseSentryTest () {
@@ -22,8 +23,8 @@ class SentryContextProviderTest : BaseSentryTest() {
22
23
class SentryContextOnCreateTest : BaseSentryTest () {
23
24
@Test
24
25
fun `onCreate initializes applicationContext` () {
25
- // Simple call to the lateinit applicationContext to make sure it's initialized
26
- applicationContext
26
+ // Simple call to the applicationContext to make sure it's initialized
27
+ assertNotNull( applicationContext)
27
28
}
28
29
}
29
30
You can’t perform that action at this time.
0 commit comments