android-maps-utils: Fatal Exception: android.content.res.Resources$NotFoundException: Resource ID

Summary:

The map randomly crashes while setting up the cluster manager and rendering the clusters.

Steps to reproduce: This is happening intermittently so it is hard to reproduce. See logs for more details.

Crashlytics Logs

Fatal Exception: android.content.res.Resources$NotFoundException: Resource ID #0x7f08005e at android.content.res.ResourcesImpl.getValueForDensity + 240(ResourcesImpl.java:240) at android.content.res.Resources.getDrawableForDensity + 885(Resources.java:885) at android.content.res.Resources.getDrawable + 828(Resources.java:828) at android.content.res.Resources.getDrawable + 803(Resources.java:803) at com.google.maps.android.ui.BubbleDrawable.(BubbleDrawable.java:3) at com.google.maps.android.ui.IconGenerator.(IconGenerator.java:3) at com.google.maps.android.clustering.view.DefaultClusterRenderer.(DefaultClusterRenderer.java:12) at com.google.maps.android.clustering.ClusterManager.(ClusterManager.java:9) at com.google.maps.android.clustering.ClusterManager.(ClusterManager.java:9) at com.ojoelectric.ojo.ui.map.ScooterMapFragment.onMapReady + 179(ScooterMapFragment.java:179) at com.google.android.gms.maps.zzak.zza(zzak.java:1) at com.google.android.gms.maps.internal.zzaq.dispatchTransaction(zzaq.java:1) at com.google.android.gms.internal.maps.zzb.onTransact + 22(zzb.java:22) at android.os.Binder.transact + 656(Binder.java:656) at hq.b + 14(hq.java:14) at com.google.android.gms.maps.internal.be.a + 4(be.java:4) at com.google.maps.api.android.lib6.impl.bj.run + 4(bj.java:4) at android.os.Handler.handleCallback + 790(Handler.java:790) at android.os.Handler.dispatchMessage + 99(Handler.java:99) at android.os.Looper.loop + 175(Looper.java:175) at android.app.ActivityThread.main + 6724(ActivityThread.java:6724) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 438(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main + 810(ZygoteInit.java:810)

Device and Android version:

  • LG Premiere Pro and LG Stylo 4 (8.1.0)

  • Galaxy J7 Crown (8.0) and Galaxy S8+ (7.1.2) and Galaxy Tab E 8.0 (7.1.1)

  • ZTE ZFive C LTE (7.1.1) and Z999 (7.1.2)

  • OnePlus 5T and OnePlus 6 (9.0)

  • Pixel XL (9.0)

  • AlcatelOneTouch (7.0)

  • XiaoMi 5 (8.0)

  • Coolpad Legacy (9.0)

I am using the following google map dependencies:

ext.googlePlayServicesVersion = "16.0.0"

implementation "com.google.android.gms:play-services-location:$googlePlayServicesVersion"
implementation "com.google.android.gms:play-services-maps:$googlePlayServicesVersion"
kapt "com.google.android.gms:play-services-maps:$googlePlayServicesVersion"
implementation 'com.google.maps.android:android-maps-utils:0.5'

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 9
  • Comments: 30 (11 by maintainers)

Commits related to this issue

Most upvoted comments

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Found this today in a Pixel 3A (Android 11 API 30) using play_services_maps 17.0.0 and android_maps_utils 2.1.0:

android.content.res.Resources$NotFoundException: Resource ID #0x7f060016 type #0x3 is not valid
        at android.content.res.Resources.getDimensionPixelSize(Resources.java:827)
        at com.google.maps.api.android.lib6.impl.av.n(:com.google.android.gms.dynamite_mapsdynamite@204215097@20.42.15 (150400-0):5)
        at com.google.maps.api.android.lib6.impl.fd.<init>(:com.google.android.gms.dynamite_mapsdynamite@204215097@20.42.15 (150400-0):6)
        at com.google.maps.api.android.lib6.impl.bm.ay(:com.google.android.gms.dynamite_mapsdynamite@204215097@20.42.15 (150400-0):14)
        at com.google.maps.api.android.lib6.impl.cx.c(:com.google.android.gms.dynamite_mapsdynamite@204215097@20.42.15 (150400-0):2)
        at com.google.android.gms.maps.internal.q.aW(:com.google.android.gms.dynamite_mapsdynamite@204215097@20.42.15 (150400-0):15)
        at dn.onTransact(:com.google.android.gms.dynamite_mapsdynamite@204215097@20.42.15 (150400-0):4)
        at android.os.Binder.transact(Binder.java:1043)
        at com.google.android.gms.internal.maps.zza.zzb(Unknown Source:20)
        at com.google.android.gms.maps.internal.zzk.onCreate(Unknown Source:17)
        at com.google.android.gms.maps.MapView$zza.onCreate(Unknown Source:8)
        at com.google.android.gms.dynamic.zad.zaa(com.google.android.gms:play-services-base@@17.3.0:3)
        at com.google.android.gms.dynamic.zab.onDelegateCreated(com.google.android.gms:play-services-base@@17.3.0:4)
        at com.google.android.gms.maps.MapView$zzb.createDelegate(Unknown Source:16)
        at com.google.android.gms.dynamic.DeferredLifecycleHelper.zaa(com.google.android.gms:play-services-base@@17.3.0:18)
        at com.google.android.gms.dynamic.DeferredLifecycleHelper.onCreate(com.google.android.gms:play-services-base@@17.3.0:22)
        at com.google.android.gms.maps.MapView.onCreate(Unknown Source:26)

First time ever happened, same use case as the author. Build > Clean Project fixed the issue (so far).

🎉 This issue has been resolved in version 1.3.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

It looks like the root cause of this may be that in BubbleDrawable, the shadow and mask PNG resources are only defined in the drawable-xhdpi and drawable-xxhdpi folders: https://github.com/googlemaps/android-maps-utils/tree/master/library/src/main/res

The Android resources docs say:

Caution: When defining an alternative resource, make sure you also define the resource in a default configuration. Otherwise, your app might encounter runtime exceptions when the device changes a configuration. For example, if you add a string to only values-en and not values, your app might encounter a Resource Not Found exception when the user changes the default system language.

I’m guessing in some cases Android is trying to load the resources at densities other than xhdpi or xxhdpi, and as a result there isn’t a default resource to load, and therefore it throws the Resources$NotFoundException.

A counter argument to this theory is that further down the docs also say:

There is one exception to this rule: If your app’s minSdkVersion is 4 or greater, you don’t need default drawable resources when you provide alternative drawable resources with the screen density qualifier. Even without default drawable resources, Android can find the best match among the alternative screen densities and scale the bitmaps as necessary. However, for the best experience on all types of devices, you should provide alternative drawables for all three types of density.

A potential complicating factor is that Drawable getDrawable (int id) was deprecated in API level 22, with getDrawable(int, Theme) replacing it. There is also ContextCompat.getDrawable() in the Android X library.

So, perhaps the deprecated implementation isn’t properly handling resource scaling in all cases, even though the Android docs say it should work?

Instead of adding additional PNGs in the default folder which would increase the size of the library, I’m going to try fixing this at first by changing to using ContextCompat.getDrawable().

I’ll open a PR with this fix shortly. If this doesn’t fix it, we can add the PNGs in the default resource directory.

Same here in library version 3.4.0, the device is Vivo V21 5G(Android 13)

Fatal Exception: android.content.res.Resources$NotFoundException: Resource ID #0x7f070055 at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:353) at android.content.res.Resources.getDrawableForDensity(Resources.java:1078) at android.content.res.Resources.getDrawable(Resources.java:1018) at android.content.Context.getDrawable(Context.java:810) at androidx.core.content.ContextCompat$Api21Impl.getDrawable(ContextCompat.java:864) at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:483) at com.google.maps.android.ui.BubbleDrawable.<init>(BubbleDrawable.java:42) at com.google.maps.android.ui.IconGenerator.<init>(IconGenerator.java:60) at com.google.maps.android.clustering.view.DefaultClusterRenderer.<init>(DefaultClusterRenderer.java:141) at com.google.maps.android.clustering.ClusterManager.<init>(ClusterManager.java:80) at com.google.maps.android.clustering.ClusterManager.<init>(ClusterManager.java:72) at pl.dominium.base.util.map.presenter.base.ClusterMapPresenter.onMapReady(ClusterMapPresenter.kt:37) at com.google.android.gms.maps.zzaf.zzb(com.google.android.gms:play-services-maps@@18.1.0:1) at com.google.android.gms.maps.internal.zzar.zza(com.google.android.gms:play-services-maps@@18.1.0:6) at com.google.android.gms.internal.maps.zzb.onTransact(com.google.android.gms:play-services-maps@@18.1.0:3) at android.os.Binder.transact(Binder.java:1184) at fe.c(:com.google.android.gms.dynamite_mapsdynamite@232216044@23.22.16 (190400-0):2) at com.google.maps.api.android.lib6.impl.bg.run(:com.google.android.gms.dynamite_mapsdynamite@232216044@23.22.16 (190400-0):2) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:223) at android.os.Looper.loop(Looper.java:324) at android.app.ActivityThread.main(ActivityThread.java:8486) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:582) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1061)

@barbeau can’t think of another workaround for this—the approach to create a drawable-xxxhdpi makes sense to me.

@seventhmoon this issue happened on production and we are only distributing it in Google Play.

@barbeau @arriolac I have pointed our app’s map library version to 1.3.3. Thank you for the fix!

still receiving this error: Nexus 6 (Android 7.1) OnePlus GM1910 (Android 9)