MapboxGL.setTelemetryEnabled(boolean) crashes on android
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

Versions (please complete the following information):
- Platform: Android
- Platform OS: Android 10 and 11
- Device: Samsung S20 and Google pixel emulator
- Emulator/ Simulator: Same error on both
- Dev OS: OSX 10.15.4
- react-native-mapbox-gl Version: 8.1.0
- React Native Version: 0.63.4
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.
@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
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!
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.
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.
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?
Same problem with many users of ours, in Android. Can you please reopen this? Thanks.
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.
I'm still getting this issue on "@react-native-mapbox-gl/maps": "^8.6.0-beta.0"
Also getting this error using useEffect
Hello, we are also having this issue, do you need any info?
Any update on this issue? Happened in Android 12 only. Using 8.5.0
Still an issue on Android 12 using 8.5.0 and 8.6.0beta.0 as well.