maps: [Bug]: Usage of `UserLocation` causes app crash on Android when new arch is disabled

Mapbox Implementation

Mapbox

Mapbox Version

default

React Native Version

0.76.7

Platform

Android

@rnmapbox/maps version

10.1.37

Standalone component to reproduce

import React, { useEffect, useState } from "react";
import { StyleSheet, View } from "react-native";
import Mapbox from "@rnmapbox/maps";

const App = () => {
  const [ready, setReady] = useState(false);

  useEffect(() => {
    Mapbox.requestAndroidLocationPermissions()
      .then((isGranted) => {
        setReady(isGranted);
      })
      .catch(console.error);
  }, [setReady]);

  return (
    <View style={styles.page}>
      <View style={styles.container}>
        {ready ? (
          <Mapbox.MapView style={styles.map}>
            {/* ๐Ÿ‘‡ Issue goes away when removing this line. */}
            <Mapbox.UserLocation />
          </Mapbox.MapView>
        ) : null}
      </View>
    </View>
  );
};

export default App;

const styles = StyleSheet.create({
  page: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
  },
  container: {
    height: 300,
    width: 300,
  },
  map: {
    flex: 1,
  },
});

Observed behavior and steps to reproduce

The app completely crashes, with the following error message (seen via adb logs):

03-03 16:29:09.956 17182 17182 E AndroidRuntime: FATAL EXCEPTION: main
03-03 16:29:09.956 17182 17182 E AndroidRuntime: Process: com.andrewchou.rnmapsissuerepro, PID: 17182
03-03 16:29:09.956 17182 17182 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.facebook.react.bridge.CxxCallbackImpl.invoke(java.lang.Object[])' on a null object reference
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at com.rnmapbox.rnmbx.NativeRNMBXLocationModuleSpec.emitOnLocationUpdate(NativeRNMBXLocationModuleSpec.java:38)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at com.rnmapbox.rnmbx.modules.RNMBXLocationModule.access$emitOnLocationUpdate(RNMBXLocationModule.kt:18)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at com.rnmapbox.rnmbx.modules.RNMBXLocationModule$onUserLocationChangeCallback$1.onLocationChange(RNMBXLocationModule.kt:62)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at com.rnmapbox.rnmbx.location.LocationManager.onLocationChanged(LocationManager.kt:251)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at com.rnmapbox.rnmbx.location.LocationManager.onSuccess(LocationManager.kt:260)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at com.rnmapbox.rnmbx.location.LocationManager.onSuccess(LocationManager.kt:93)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at com.mapbox.android.core.location.LocationEngineCommonCompatKt$toCommonCompat$1.onSuccess(LocationEngineCommonCompat.kt:99)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at com.mapbox.android.core.location.LocationEngineCommonCompatKt$toCommonCompat$1.onSuccess(LocationEngineCommonCompat.kt:93)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at com.mapbox.common.location.compat.LocationEngineImpl$liveTrackingObserver$1$onLocationUpdateReceived$lambda-2$lambda-1$$inlined$postOrCall$1.run(LocationEngineImpl.kt:361)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:938)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:99)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:223)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:7656)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
03-03 16:29:09.956 17182 17182 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Expected behavior

App should not crash when using a component that subscribes to location updates.

Notes / preliminary analysis

Itโ€™s important to note that this seems to only be an issue when:

  1. The new arch is disabled. The issue is not present when the new arch is enabled
  2. Using 10.1.37 of this library. 10.1.36 does NOT have this issue.
  3. Using the UserLocation component. Guessing itโ€™s not necessarily only tied to that component but anything that may subscribe to location updates.

I can create a test repo if helpful, but hopefully this is enough to work with.

Additional links and references

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 6
  • Comments: 20 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Same issue on 10.1.39

@achou11 Would you please help me for this issue?

@seyedmostafahasani Iโ€™m just a mere user ๐Ÿ˜„ Up to the maintainers to figure out how to address this.

Only thing I can suggest is pinning the version to a working version, which in my case was using 10.1.36

I just downgraded to 10.1.36 as well, and it fixed the issue for me.

Same issue for me, downgrading to 10.1.36 made it working back