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") {
1414}
1515```
1616
17+ ### Fixes
18+
19+ - Don't crash app when ` applicationContext ` is not available ([ #217 ] ( https://github.com/getsentry/sentry-kotlin-multiplatform/pull/217 ) )
20+
1721### Enhancements
1822
1923- 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
1111internal actual fun initSentry (configuration : OptionsConfiguration ) {
1212 val options = SentryOptions ()
1313 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+ }
1523}
1624
17- internal lateinit var applicationContext: Context
25+ internal var applicationContext: Context ? = null
1826 private set
1927
2028public actual typealias Context = Context
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import org.junit.Before
77import org.junit.Test
88import org.junit.runner.RunWith
99import org.mockito.Mockito.mock
10+ import kotlin.test.assertNotNull
1011
1112@RunWith(AndroidJUnit4 ::class )
1213class SentryContextProviderTest : BaseSentryTest () {
@@ -22,8 +23,8 @@ class SentryContextProviderTest : BaseSentryTest() {
2223 class SentryContextOnCreateTest : BaseSentryTest () {
2324 @Test
2425 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)
2728 }
2829 }
2930
You can’t perform that action at this time.
0 commit comments