rnmapbox / maps

A Mapbox react native module for creating custom maps
MIT License
2.22k stars 838 forks source link

MapboxGL.setTelemetryEnabled(boolean) crashes on android #1231

Closed olofho closed 3 years ago

olofho commented 3 years ago

Describe the bug
Calling MapboxGL.setTelemetryEnabled(boolean) crashes on android.

To Reproduce
Call MapboxGL.setTelemetryEnabled(boolean) in componentDidMount()

Example:

import React from 'react';
import MapboxGL from '@react-native-mapbox-gl/maps';

class BugReportExample extends React.Component {

  componentDidMount() {
    MapboxGL.setTelemetryEnabled(false);
  }

  render() {
    return (
      <MapboxGL.MapView style={{flex: 1}}>

      </MapboxGL.MapView>
    );
  }
}

Expected behavior
Telemetry to be set to false and map to function

Actual behavior
iOS works fine. On Android app crashes with following exception:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'void com.mapbox.mapboxsdk.maps.b0.setUserTelemetryRequestState(boolean)' on a null object reference
       at com.mapbox.rctmgl.modules.RCTMGLModule$4.run(RCTMGLModule.java)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5421)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Screenshots

crash

Versions (please complete the following information):

airburst commented 3 years ago

I have the same issue on Android emulator and a couple of physical phones.

We cannot pass Google Play Store review because Mapbox telemetry triggers request for background location - in contravention of Google's location policy - even though we do not use background or foreground location in the app.

ferdicus commented 3 years ago

@olofho, I was unable to replicate this within our example app. What's the reproduction rate for you? Does it always happen?

What I could imagine, is, that the Mapbox instance isn't initialized yet and this call: https://github.com/react-native-mapbox-gl/maps/blob/397482d4adc7e34cea30b39151c638e418a66f89/android/rctmgl/src/main/java/com/mapbox/rctmgl/modules/RCTMGLModule.java#L339

returns null

which then is a problem in the following line: https://github.com/react-native-mapbox-gl/maps/blob/397482d4adc7e34cea30b39151c638e418a66f89/android/rctmgl/src/main/java/com/mapbox/rctmgl/modules/RCTMGLModule.java#L340

olofho commented 3 years ago

Hi @ferdicus !

For me it is not intermittent, it happens on every launch. My app has a login screen and once log in is successful I navigate to a map-page that tries to set telemetry in componentDidMount() which causes a crash on android. As a workaround I instead set telemetry when map finished loading which seems to work: onDidFinishLoadingMap={() => MapboxGL.setTelemetryEnabled(false)}

Thank you for all the work you guys put on this library, I use it a lot and it's usually flawless!

airburst commented 3 years ago

I can corroborate @olofho 's results.

Basically, the MapboxGL object is always null when attempting MapboxGL.setTelemetry(false) in Android only; it is fine in iOS.

I have run this method in a useEffect, componentDidMount and onDidFinishLoading; in every case MapboxGL is definitely not null, but this is the error reported by react native.

Thanks again for your great work.

stale[bot] commented 3 years ago

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.

Micgaw commented 2 years ago

Hi,

I've experience same problem as @olofho just in Android 12. For me it work just fine in Android 10 & Android 11.

Versions (please complete the following information):

Platform: Android Platform OS: Android 12 Device: Android emulator & GooglePixel Emulator/ Simulator: Same error on both Dev OS: Windows 10 Pro react-native-mapbox-gl Version: 8.5.0 React Native Version: 0.63.4

Also as @airburst described moving MapboxGL.setTelemetryEnabled(false) to onDidFinishLoadingMap, useEffect or componentDidMount doesn't help. Telemetry object is always null and it causes application crash.

Can we reopen this issue?

afilp commented 2 years ago

Same problem with many users of ours, in Android. Can you please reopen this? Thanks.

stanjhae commented 2 years ago

The issue seems to only occur in Android 12. Mapbox upgraded telemetry dependency to 8.1.0 to be compatible with Android 12 so I did the same.

https://github.com/mapbox/mapbox-gl-native-android/blob/main/CHANGELOG.md#962---july-7-2021

Adding this implementation 'com.mapbox.mapboxsdk:mapbox-android-telemetry:8.1.0' to android/app/build.gradle fixed my problem.

jhu7235 commented 2 years ago

I'm still getting this issue on "@react-native-mapbox-gl/maps": "^8.6.0-beta.0"

Tim4497 commented 2 years ago

Also getting this error using useEffect

thomasgrivet commented 2 years ago

Hello, we are also having this issue, do you need any info?

HeavenMin commented 2 years ago

Any update on this issue? Happened in Android 12 only. Using 8.5.0

Dantalion commented 2 years ago

Still an issue on Android 12 using 8.5.0 and 8.6.0beta.0 as well.