maplibre / maplibre-native

MapLibre Native - Interactive vector tile maps for iOS, Android and other platforms.
https://maplibre.org
BSD 2-Clause "Simplified" License
1.07k stars 314 forks source link

CameraPosition.createFromParcel crashes on Android API level 33 when R8 fullMode is enabled #1276

Open DonTomika opened 1 year ago

DonTomika commented 1 year ago

Describe the bug As of this commit, both CameraPosition and VisibleRegion uses a variant of readParcelable which was introduced in Android 13 (API Level 33). However, this method has a known compatibility issue with R8 fullMode, as described here.

As a result, the app crashes with the following exception whenever this code path gets invoked:

Exception java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Class.isInterface()' on a null object reference
  at java.lang.Class.isAssignableFrom (Class.java:589)
  at android.os.Parcel.readParcelableCreatorInternal (Parcel.java:4865)
  at android.os.Parcel.readParcelableInternal (Parcel.java:4778)
  at android.os.Parcel.readParcelable (Parcel.java:4769)
  at com.mapbox.mapboxsdk.camera.CameraPosition$Companion$CREATOR$1.createFromParcel (CameraPosition.java:523)
  at com.mapbox.mapboxsdk.camera.CameraPosition$Companion$CREATOR$1.createFromParcel (CameraPosition.java:523)
  at android.os.Parcel.readParcelableInternal (Parcel.java:4787)
  at android.os.Parcel.readParcelable (Parcel.java:4755)
  at com.mapbox.mapboxsdk.maps.MapboxMapOptions.<init> (MapboxMapOptions.java:2)
  at com.mapbox.mapboxsdk.maps.MapboxMapOptions.<init> (MapboxMapOptions.java:2)
  at com.mapbox.mapboxsdk.maps.MapboxMapOptions$1.createFromParcel (MapboxMapOptions.java:404)
  at com.mapbox.mapboxsdk.maps.MapboxMapOptions$1.createFromParcel (MapboxMapOptions.java:404)
  at android.os.Parcel.readParcelableInternal (Parcel.java:4787)
  at android.os.Parcel.readValue (Parcel.java:4544)
  at android.os.Parcel.readValue (Parcel.java:4324)
  at android.os.Parcel.-$$Nest$mreadValue
  at android.os.Parcel$LazyValue.apply (Parcel.java:4422)
  at android.os.Parcel$LazyValue.apply (Parcel.java:4381)
  at android.os.BaseBundle.getValueAt (BaseBundle.java:394)
  at android.os.BaseBundle.getValue (BaseBundle.java:374)
  at android.os.BaseBundle.getValue (BaseBundle.java:357)
  at android.os.BaseBundle.getValue (BaseBundle.java:350)
  at android.os.Bundle.getParcelable (Bundle.java:913)
  at com.mapbox.mapboxsdk.utils.MapFragmentUtils.resolveArgs (MapFragmentUtils.java:94)
(user code)

To Reproduce One way to reproduce this issue is to use MapFragmentUtils.createFragmentArgs either directly or indirectly, e.g. by calling MapFragment.newInstance and passing a MapLibreMapOptions instance.

The following conditions should also be met for the crash to happen:

Platform information (please complete the following information): This issue only affects devices running Android 13 (API Level 33).

Additional context The following versions are affected:

One possible workaround would be to use BundleCompat.getParcelable(Bundle, String, Class) from androidx.core:core-ktx:1.10.0, which falls back to the old behaviour on API levels <34.

louwers commented 1 year ago

Thanks for reporting this @DonTomika :pray: