IllegalArgumentException: Unmanaged descriptor using gms.maps.model.Marker.setIcon

后端 未结 10 2037
眼角桃花
眼角桃花 2020-12-14 05:39

I have an app that use android-maps-utils and glide for marker icons.
I got an error report using Firebase crash reporting which I can\'t track in source code because

相关标签:
10条回答
  • 2020-12-14 06:08

    I was too getting same exception and setting silent exception with try/catch would not have been solution as user is not able to see current location in my case:

    java.lang.IllegalArgumentException: Unmanaged descriptor at com.google.maps.api.android.lib6.common.k.b(:com.google.android.gms.DynamiteModulesB:162) at com.google.maps.api.android.lib6.impl.o.c(:com.google.android.gms.DynamiteModulesB:75) at com.google.maps.api.android.lib6.impl.db.a(:com.google.android.gms.DynamiteModulesB:334) at com.google.android.gms.maps.model.internal.q.onTransact(:com.google.android.gms.DynamiteModulesB:204) at android.os.Binder.transact(Binder.java:361) at com.google.android.gms.maps.model.internal.zzf$zza$zza.zzL(Unknown Source) at com.google.android.gms.maps.model.Marker.setIcon(Unknown Source)

    What I was doing :

    Minimize the map fragment screen by pressing home button and then starting app from launcher.

    What code was doing:

    Checking is marker is not null and location is not null set location and icon.

         if (markerCurrentLocation == null && googleMap != null) {
                markerCurrentLocation = googleMap.addMarker(new MarkerOptions()
                        .position(new LatLng(0.0, 0.0))
                        .icon(null));
                markerCurrentLocation.setTag(-101);
           }
    
             if (markerCurrentLocation != null && location != null) {
                    markerCurrentLocation.setPosition(new LatLng(location.getLatitude(), location.getLongitude()));
                    if (ORDER_STARTED) {
                       markerCurrentLocation.setIcon(CURRENT_MARKER_ORANGE);
                    } else {
                        markerCurrentLocation.setIcon(CURRENT_MARKER_GRAY);
                    }       
             }
    

    Exception was at : markerCurrentLocation.setIcon();

    How I got rid of this exception:

    I removed the following line

     if (markerCurrentLocation == null && googleMap != null) 
    

    Which means I am initializing marker again. If you encounter this error, try not to setIcon() on old marker, instead inflate new marker and then use setIcon().

    Explanation:

    I ASSUME (not sure) exception reason was if code is trying to setIcon() again on marker on which it is already set , at particular instance like in my case Map is resuming or may be in your case marker goes out of visible part of map and comes in or something similar.

    For sure there is no problem with descriptor we get from method BitmapDescriptorFactory.fromBitmap() or BitmapDescriptorFactory.fromResource(). As the exception hints, descriptor got unmanaged on a old marker, better use new one.

    0 讨论(0)
  • 2020-12-14 06:11

    When clearing the map with

        googleMap.clear();
    

    **remove any reference to all the markers** on the map. I had the problem and figured out that the problem was with my code which I forgot to remove reference to a marker and tried to change icon of a cleared Marker

    0 讨论(0)
  • 2020-12-14 06:13

    I have the same environment (maps-utils + custom renderer + Glide) and the same error IllegalArgumentException: Unmanaged descriptor.

    I solved the error by checking if the marker is "valid" before setting the icon, using the methods DefaultClusterRenderer.getCluster(Marker) and DefaultClusterRenderer.getClusterItem(Marker). If both return null, I don't do anything on the onResourceReady(...) method.

    In your case I would try the following change to CustomSimpleTarget:

    private class CustomSimpleTarget extends SimpleTarget<GlideDrawable> {
        Sucursal sucursal;
        Marker markerToChange = null;
    
        @Override
        public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
    
            if (getCluster(markerToChange) != null || getClusterItem(markerToChange) != null) {
    
                mImageView.setImageDrawable(resource);
                //currentSelectedItem is the current element selected in the map (Sucursal type)
                //mIconGenerator is a: CustomIconGenerator extends IconGenerator
                if (currentSelectedItem != null && sucursal.idalmacen.contentEquals(currentSelectedItem.idalmacen))
                    mIconGenerator.customIconBackground.useSelectionColor(true, ContextCompat.getColor(mContext, R.color.colorAccent));
                else
                    mIconGenerator.customIconBackground.useSelectionColor(false, 0);
    
                Bitmap icon = mIconGenerator.makeIcon();
    
                //GlideShortcutDrawable is a WeakReference<>(drawable)
                sucursal.setGlideShortCutDrawable(resource);
                markerToChange.setIcon(BitmapDescriptorFactory.fromBitmap(icon));
            }
        }
    }
    

    PS.: I can reproduce the problem easily on a slow device and clearing the app cache before testing (to force Glide to load from network). Then I open the map and perform some zoom in/out before any markers load.

    0 讨论(0)
  • 2020-12-14 06:13

    Had the same exception after adding cluster. I fixed it by calling:

    clusterManager.clearItems()
    

    Instead of calling method I used before, without cluster:

    googleMap.clear();
    
    0 讨论(0)
提交回复
热议问题