googlemaps / android-maps-compose

Jetpack Compose composables for the Maps SDK for Android
https://developers.google.com/maps/documentation/android-sdk/maps-compose
Apache License 2.0
1.15k stars 137 forks source link

StrictMode detectDiskReads() causes Google Maps to be extremely laggy and ANRs #159

Open mkpazon opened 2 years ago

mkpazon commented 2 years ago

Thanks for stopping by to let us know something could be better!


PLEASE READ

If you have a support contract with Google, please create an issue in the support console. This will ensure a timely response.

Discover additional support services for the Google Maps Platform, including developer communities, technical guidance, and expert support at the Google Maps Platform support resources page.

If your bug or feature request is not related to this particular library, please visit the Google Maps Platform issue trackers.

Check for answers on StackOverflow with the google-maps tag.


Please be sure to include as much information as possible:

Environment details

Library version: Tested with Maps Compose 1.2.0 and 2.2.1

Steps to reproduce

  1. Enable detect disk reads in StrictMode (see code example)

Code example

StrictMode.setThreadPolicy(
    ThreadPolicy.Builder()
        .detectDiskReads()
        .build()
)
hlandim commented 1 year ago

I'm getting this log when using StrictMode:

StrictMode policy violation: android.os.strictmode.IncorrectContextUseViolation: The API:ViewConfiguration needs a proper configuration. Use UI contexts such as an activity or a context created via createWindowContext(Display, int, Bundle) or  createConfigurationContext(Configuration) with a proper configuration.
                                                                                            at android.os.StrictMode.onIncorrectContextUsed(StrictMode.java:2261)
                                                                                            at android.os.StrictMode.assertConfigurationContext(StrictMode.java:2297)
                                                                                            at android.view.ViewConfiguration.get(ViewConfiguration.java:522)
                                                                                            at android.view.View.<init>(View.java:5330)
                                                                                            at android.view.TextureView.<init>(TextureView.java:146)
                                                                                            at com.google.maps.api.android.lib6.gmm6.vector.av.<init>(:com.google.android.gms.dynamite_mapsdynamite@231613044@23.16.13 (190400-0):1)
                                                                                            at com.google.maps.api.android.lib6.gmm6.vector.ac.<init>(:com.google.android.gms.dynamite_mapsdynamite@231613044@23.16.13 (190400-0):1)
                                                                                            at com.google.maps.api.android.lib6.gmm6.api.ac.<init>(:com.google.android.gms.dynamite_mapsdynamite@231613044@23.16.13 (190400-0):1)
                                                                                            at com.google.maps.api.android.lib6.impl.bk.aD(:com.google.android.gms.dynamite_mapsdynamite@231613044@23.16.13 (190400-0):54)
                                                                                            at com.google.maps.api.android.lib6.impl.cu.d(:com.google.android.gms.dynamite_mapsdynamite@231613044@23.16.13 (190400-0):2)
                                                                                            at com.google.android.gms.maps.internal.q.bb(:com.google.android.gms.dynamite_mapsdynamite@231613044@23.16.13 (190400-0):21)

This is my code.

GoogleMap(
        modifier = Modifier
            .fillMaxSize()
            .background(color = Color.Gray),
        cameraPositionState = cameraPositionState,
        contentPadding = paddings,
        uiSettings = mapSettings,
    ) {
        latLng?.let {
            VehicleMarker(it, onSetupEvent)
            MapEffect(latLng) {
                cameraPositionState.animate(
                    CameraUpdateFactory.newLatLngZoom(latLng, 16f),
                )
            }
        }
    }
ulfandersson commented 11 months ago

I see the same issue with maps-compose 3.1.1.

My current workaround where GoogleMaps composable is used:

  if (strictModeEnabled) {
       DisposableEffect(Unit) {
           val prevThreadPolicy = StrictMode.allowThreadDiskReads()
           onDispose {
               StrictMode.setThreadPolicy(prevThreadPolicy)
           }
       }
   }
bubenheimer commented 11 months ago

@hlandim your StrictMode problem looks very different from what this issue is about. Consider creating a new issue?