maps icon indicating copy to clipboard operation
maps copied to clipboard

[Bug]: ImageSource crashes on Android in release mode

Open matthieucan opened this issue 1 year ago • 5 comments

Mapbox Implementation

Mapbox

Mapbox Version

11.4.1

React Native Version

0.75.1

Platform

Android

@rnmapbox/maps version

#main

Standalone component to reproduce

import React from 'react';
import {
  MapView,
  ShapeSource,
  LineLayer,
  Camera,
} from '@rnmapbox/maps';

const aLine = {
  type: 'LineString',
  coordinates: [
    [-74.00597, 40.71427],
    [-74.00697, 40.71527],
  ],
};

class BugReportExample extends React.Component {
  render() {
    return (
      <MapView style={{flex: 1}}>
        <Camera centerCoordinate={[-74.00597, 40.71427]} zoomLevel={14} />
        <ShapeSource id="idStreetLayer" shape={aLine}>
          <LineLayer id="idStreetLayer" />
        </ShapeSource>
      </MapView>
    );
  }
}

Observed behavior and steps to reproduce

Note that I did not fill the standalone component to reproduce, as it requires at least 1 external asset (an image).

When running a release version of Android, ImageSource crashes. This is not the case for the debug mode, i.e. yarn start.

This can be reproduced in the example app within this repository:

cd example
(cd android && ./gradlew assembleRelease)
adb install ./android/app/build/outputs/apk/release/app-release.apk

Navigate to Fill/Raster Layer > Image Overlay.

The logs show:

10-29 00:17:51.528 17778 17778 E AndroidRuntime: FATAL EXCEPTION: main
10-29 00:17:51.528 17778 17778 E AndroidRuntime: Process: com.rnmapboxglexample, PID: 17778
10-29 00:17:51.528 17778 17778 E AndroidRuntime: java.lang.RuntimeException: ImageSource without URL not supported in v10, resourceId is not supported
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at com.rnmapbox.rnmbx.components.styles.sources.RNMBXImageSource.makeSource(RNMBXImageSource.kt:22)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at com.rnmapbox.rnmbx.components.styles.sources.RNMBXImageSource.makeSource(RNMBXImageSource.kt:11)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at com.rnmapbox.rnmbx.components.styles.sources.RNMBXSource.addToMap(RNMBXSource.kt:128)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at com.rnmapbox.rnmbx.components.styles.sources.RNMBXSource$addToMap$2.onStyleLoaded(RNMBXSource.kt:151)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at com.mapbox.maps.MapboxMap.getStyle(MapboxMap.kt:360)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at com.rnmapbox.rnmbx.components.styles.sources.RNMBXSource.addToMap(RNMBXSource.kt:149)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at com.rnmapbox.rnmbx.components.mapview.RNMBXMapView.addFeaturesToMap(RNMBXMapView.kt:520)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at com.rnmapbox.rnmbx.components.mapview.RNMBXMapView.styleLoaded(RNMBXMapView.kt:287)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at com.rnmapbox.rnmbx.components.mapview.RNMBXMapView.access$styleLoaded(RNMBXMapView.kt:203)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at com.rnmapbox.rnmbx.components.mapview.RNMBXMapView$applyStyleURL$2.onStyleLoaded(RNMBXMapView.kt:673)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at com.mapbox.maps.StyleObserver.onStyleLoaded(StyleObserver.kt:99)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at com.mapbox.maps.NativeObserver.notify(NativeObserver.kt:63)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at android.os.MessageQueue.nativePollOnce(Native Method)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at android.os.MessageQueue.next(MessageQueue.java:339)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at android.os.Looper.loopOnce(Looper.java:179)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:344)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:8212)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
10-29 00:17:51.528 17778 17778 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)

Expected behavior

ImageSource works in both debug mode and release mode.

Notes / preliminary analysis

No response

Additional links and references

No response

matthieucan avatar Oct 28 '24 23:10 matthieucan

I have the same problem on

  • rnmapbox 10.1.38
  • RN 0.76.7

Do you have any fix or workaround?

vovka-s avatar May 05 '25 08:05 vovka-s

Unfortunately no, but would certainly love to.

matthieucan avatar May 17 '25 22:05 matthieucan

I encountered the same issue. It works if I upload the image to a domain and use HTTPS. However, my system is offline (no internet), so I can only use images bundled within the app. Has there been any workaround for this yet?

waladylan avatar Jul 14 '25 10:07 waladylan

Up, still an issue, need some help on this one because we the ImageSource to work even offline.

AskaHD avatar Sep 19 '25 07:09 AskaHD

It works if I upload the image to a domain and use HTTPS.

I confirm this workaround works, but of course it's less convenient and not always suitable.

matthieucan avatar Nov 19 '25 22:11 matthieucan