mapbox / mapbox/mapbox-maps-android

MapboxSDKCommon.getContext crash

Offen
#2,455 14 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

auto-triaged bug :beetle: needs info
Vorherrschende Sprache
Kotlin
Sterne
578
Forks
161
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

## Environment

- Android OS version: 14
- Devices affected: Mainly Samsung devices
- Maps SDK Version: 10.5.0

## Observed behavior and steps to reproduce

In crashlytics I receive a bunch of crashes from a small amount of users using my app where the app randomly crashes with the following stacktrace:
```
Exception java.lang.ExceptionInInitializerError:
at com.mapbox.common.location.LocationUpdatesReceiver$service$2.invoke (LocationUpdatesReceiver.kt:10)
at com.mapbox.common.location.LocationUpdatesReceiver$service$2.invoke (LocationUpdatesReceiver.kt:9)
at kotlin.SynchronizedLazyImpl.getValue (LazyJVM.kt)
at com.mapbox.common.location.LocationUpdatesReceiver.getService (LocationUpdatesReceiver.kt)
at com.mapbox.common.location.LocationUpdatesReceiver.onReceive (LocationUpdatesReceiver.kt)
at android.app.ActivityThread.handleReceiver (ActivityThread.java:4719)
at android.app.ActivityThread.-$$Nest$mhandleReceiver
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2448)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loopOnce (Looper.java:257)
at android.os.Looper.loop (Looper.java:368)
at android.app.ActivityThread.main (ActivityThread.java:8839)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:572)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1049)
Caused by Bb.e: lateinit property appContext has not been initialized
at com.mapbox.common.MapboxSDKCommon.getContext (MapboxSDKCommon.kt)
at com.mapbox.common.location.LocationServiceImpl. (LocationServiceImpl.kt)
```

From what I was able to gather this happens at random, sometimes when the app is backgrounded or sometimes when the app is left open. I tried many combinations to get it to happen to me but I myself am unable to reproduce it or even trigger it.

I'm not doing anything special, below is my code to initialize the map using Compose:
```
val mapState = rememberMapState {
gesturesSettings = GesturesSettings.Builder()
.setPinchScrollEnabled(false)
.build()
}

MapboxMap(
modifier = Modifier.fillMaxSize(),
composeMapInitOptions = ComposeMapInitOptions(
mapOptions = MapOptions.Builder()
.contextMode(ContextMode.UNIQUE)
.viewportMode(ViewportMode.DEFAULT)
.build()
),
mapState = mapState,
scaleBar = { /* No scalebar */ },
logo = { Logo(contentPadding = PaddingValues(20.dp)) },
attribution = {
Attribution(
iconColor = theme.colorScheme.secondary,
contentPadding = PaddingValues(
start = 110.dp,
top = 0.dp,
end = 0.dp,
bottom = 20.dp
)
)
}
) {
// Load the style on the fly.
MapEffect(styleUrl) {
it.mapboxMap.loadStyle(styleUrl)
}
}
```

I receive the styleURL from a viewModel.

Then there's also a button added that toggles the user location. That's being done this way:
```
MapEffect(isShowingUsersLocation) {
it.location.updateSettings {
enabled = isShowingUsersLocation
}
}
```

## Expected behavior

A crash not related to the location update service.

## Notes / preliminary analysis

I run the app through R8, but can't tell if that's the reason of the crashes as I'm unable to reproduce it in either an R8 built or a non R8 built.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit dem Stacktrace durch LocationUpdatesReceiver.kt und untersuchen Sie MapboxSDKCommon.kt und LocationServiceImpl.kt. Konzentrieren Sie sich darauf, wann appContext initialisiert wird, bevor der Standortdienst geladen wird. Reproduzieren Sie die im Issue beschriebenen Background- und Receiver-Pfade oder leiten Sie deren Verhalten her. Die Aufgabe ist abgeschlossen, wenn der Standortaktualisierungsdienst nicht mehr abstürzt, weil appContext nicht initialisiert wurde.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
android, kotlin
Bereich
mobile-dev
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.