Environment details
- Maps Compose (
GoogleMap with GoogleMapOptions().liteMode(true))
- Android 12 / 13 (production devices), Android 15 emulator (Google Play image, API 35)
com.google.maps.android:maps-compose:8.6.0 (the relevant code is unchanged in 9.0.0), com.google.android.gms:play-services-maps:20.0.0
The crash depends on the Google Play services maps module version on the device:
Maps module (policy_maps_core_dynamite) |
Result |
| 24.16 (Play services 24.23.35, emulator) |
Crashes |
| 25.06 / 25.34 (production devices) |
Crashes |
| 26.x (Play services 26.11 emulator, 26.36 Pixel) |
No crash, color scheme is ignored |
So most devices are fine, but devices whose Play services have not been updated for a while crash every time a Lite mode map is shown.
Steps to reproduce
- Use maps-compose 8.6.0 and show a
GoogleMap in Lite mode without passing mapColorScheme (the default).
- Run on a device with an older Play services maps module.
To reproduce on an emulator: create an AVD from the API 35 Google Play system image, which ships Play services 24.23.35, and do not sign in to a Google account so Play services is not updated.
- The app crashes as soon as the map is created (light or dark system theme, both crash).
The bundled LiteModeActivity sample does not pass mapColorScheme either, so it goes through the same code path.
Cause
This looks like a regression of #601, which was fixed by #603 (removing the default MapColorScheme).
#986 made FOLLOW_SYSTEM the default again, for a good reason (maps without an explicit mapColorScheme were stuck in light mode), but the change also reaches Lite mode maps:
Lite mode does not support map color schemes (Lite mode docs).
Recent Play services ignore the call, but older ones throw UnsupportedOperationException, either at MapView.onCreate (from the options) or at the MapUpdater setter.
docs/lite-mode-dark-theme.md (#989) says the SDK ignores MapColorScheme for Lite mode maps, which only holds on recent Play services.
Proposed fix
Keep FOLLOW_SYSTEM as the default from #986, and skip the color scheme only for Lite mode maps:
- In the
AndroidView factory, apply mapColorScheme to GoogleMapOptions only when opts.liteMode != true.
- In
MapUpdater, skip map.mapColorScheme = it when the map is in Lite mode (the factory already sets cameraPositionState.isLiteMode).
Non-Lite maps keep following the system theme, and Lite mode maps behave the same on every Play services version as they already do on recent ones.
A try/catch around setMapColorScheme would not be enough, because with maps module 25.34 the crash happens inside MapView.onCreate from the options.
Lite mode maps that should follow the theme can keep using mapStyleOptions, as described in docs/lite-mode-dark-theme.md.
Workaround until fixed: pass mapColorScheme = null explicitly for Lite mode maps.
Code example
GoogleMap(
modifier = Modifier.size(108.dp, 76.dp),
cameraPositionState = rememberCameraPositionState {
position = CameraPosition.fromLatLngZoom(LatLng(35.681236, 139.767125), 13f)
},
googleMapOptionsFactory = { GoogleMapOptions().liteMode(true) },
// mapColorScheme not specified -> defaults to FOLLOW_SYSTEM in 8.6.0 -> crash
// mapColorScheme = null, // workaround
)
Stack trace
Production device, maps module 25.34 (crashes at MapView.onCreate):
java.lang.UnsupportedOperationException: setMapColorScheme not supported in Lite mode.
at com.google.maps.api.android.lib6.lite.l.B (:com.google.android.gms.policy_maps_core_dynamite@253425407@253425402025.797495247.797495247:15)
at com.google.maps.api.android.lib6.impl.cg.N (:com.google.android.gms.policy_maps_core_dynamite@253425407@253425402025.797495247.797495247:10)
at com.google.maps.api.android.lib6.impl.cg.aW (:com.google.android.gms.policy_maps_core_dynamite@253425407@253425402025.797495247.797495247:290)
at com.google.maps.api.android.lib6.impl.em.d (:com.google.android.gms.policy_maps_core_dynamite@253425407@253425402025.797495247.797495247:12)
at com.google.android.gms.maps.internal.r.br (:com.google.android.gms.policy_maps_core_dynamite@253425407@253425402025.797495247.797495247:158)
at m140.bat.onTransact (:com.google.android.gms.policy_maps_core_dynamite@253425407@253425402025.797495247.797495247:21)
at android.os.Binder.transact (Binder.java:1164)
at com.google.android.gms.internal.maps.zza.zzc (zza.java:2)
at com.google.android.gms.maps.internal.zzl.onCreate (zzl.java:3)
at com.google.android.gms.maps.zzah.onCreate (zzah.java:3)
at com.google.android.gms.dynamic.zac.zab (com.google.android.gms:play-services-base@@18.9.0:1)
at com.google.android.gms.dynamic.zaa.onDelegateCreated (com.google.android.gms:play-services-base@@18.9.0:3)
at com.google.android.gms.maps.zzai.zzb (zzai.java:5)
at com.google.android.gms.maps.zzai.createDelegate (zzai.java:1)
at com.google.android.gms.dynamic.DeferredLifecycleHelper.zaf (DeferredLifecycleHelper.java:6)
at com.google.android.gms.dynamic.DeferredLifecycleHelper.onCreate (DeferredLifecycleHelper.java:1)
at com.google.android.gms.maps.MapView.onCreate (com.google.android.gms:play-services-maps@@20.0.0:4)
at com.google.maps.android.compose.MapLifecycleEventObserver.invokeEvent (MapLifecycleEventObserver.java:434)
at com.google.maps.android.compose.MapLifecycleEventObserver.moveUp (MapLifecycleEventObserver.java:429)
...
Emulator, maps module 24.16 (crashes at the MapUpdater setter):
java.lang.UnsupportedOperationException: setMapColorScheme not supported in Lite mode.
at com.google.maps.api.android.lib6.lite.l.A(:com.google.android.gms.policy_maps_core_dynamite@241610205@241610202042.636179997.636179997:10)
at com.google.maps.api.android.lib6.impl.cp.M(:com.google.android.gms.policy_maps_core_dynamite@241610205@241610202042.636179997.636179997:16)
at com.google.maps.android.compose.MapUpdaterKt$MapUpdater$1$2$15.invoke(MapUpdater.kt:142)
...
Thanks!
Environment details
GoogleMapwithGoogleMapOptions().liteMode(true))com.google.maps.android:maps-compose:8.6.0(the relevant code is unchanged in 9.0.0),com.google.android.gms:play-services-maps:20.0.0The crash depends on the Google Play services maps module version on the device:
policy_maps_core_dynamite)So most devices are fine, but devices whose Play services have not been updated for a while crash every time a Lite mode map is shown.
Steps to reproduce
GoogleMapin Lite mode without passingmapColorScheme(the default).To reproduce on an emulator: create an AVD from the API 35 Google Play system image, which ships Play services 24.23.35, and do not sign in to a Google account so Play services is not updated.
The bundled
LiteModeActivitysample does not passmapColorSchemeeither, so it goes through the same code path.Cause
This looks like a regression of #601, which was fixed by #603 (removing the default
MapColorScheme).#986 made
FOLLOW_SYSTEMthe default again, for a good reason (maps without an explicitmapColorSchemewere stuck in light mode), but the change also reaches Lite mode maps:GoogleMap.kt: theAndroidViewfactory (added in fix(maps-compose): apply mapColorScheme to GoogleMapOptions during MapView creation #976) writesmapColorSchemeintoGoogleMapOptionswhengoogleMapOptionsFactorydid not set it, regardless ofliteMode.MapUpdater.kt:set(mapColorScheme)callsmap.mapColorScheme = itwhenever the value is non-null, regardless ofliteMode.Lite mode does not support map color schemes (Lite mode docs).
Recent Play services ignore the call, but older ones throw
UnsupportedOperationException, either atMapView.onCreate(from the options) or at theMapUpdatersetter.docs/lite-mode-dark-theme.md(#989) says the SDK ignoresMapColorSchemefor Lite mode maps, which only holds on recent Play services.Proposed fix
Keep
FOLLOW_SYSTEMas the default from #986, and skip the color scheme only for Lite mode maps:AndroidViewfactory, applymapColorSchemetoGoogleMapOptionsonly whenopts.liteMode != true.MapUpdater, skipmap.mapColorScheme = itwhen the map is in Lite mode (the factory already setscameraPositionState.isLiteMode).Non-Lite maps keep following the system theme, and Lite mode maps behave the same on every Play services version as they already do on recent ones.
A try/catch around
setMapColorSchemewould not be enough, because with maps module 25.34 the crash happens insideMapView.onCreatefrom the options.Lite mode maps that should follow the theme can keep using
mapStyleOptions, as described indocs/lite-mode-dark-theme.md.Workaround until fixed: pass
mapColorScheme = nullexplicitly for Lite mode maps.Code example
Stack trace
Production device, maps module 25.34 (crashes at
MapView.onCreate):Emulator, maps module 24.16 (crashes at the
MapUpdatersetter):Thanks!