Android 12 crash: MapboxGL.setTelemetryEnabled(boolean) causes NullPointerException
Describe the bug
Calling MapboxGL.setTelemetryEnabled(boolean) crashes on android. In logcat I can see that Telemetry is null and it reproduce even if I wait for map to load.
To Reproduce
Call MapboxGL.setTelemetryEnabled(boolean) in componentDidMount(), useEffect(), or `onDidFinishLoadingMap().
Example:
import React from 'react';
import MapboxGL from '@react-native-mapbox-gl/maps';
const BugReportExample = () => {
useEffect(() => {
MapboxGL.setTelemetryEnabled(false);
}, [])
return (
<MapboxGL.MapView style={{flex: 1}} />
);
}
Expected behavior
Map initializes and mapbox telemetry is off.
Actual behavior App crashes on Android 12 (everytime).
Screenshots

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
Additional context Problem is similar to issue: #1231 just reproduces only on Android 12
We are also seeing this, but only after changing the compileSdkVersion to 31, from 30.
I think this is related to this: https://github.com/mapbox/mapbox-gl-native-android/blob/main/CHANGELOG.md#962---july-7-2021
Update telemetry to 8.1.0 (okhttp3 variant) and events-core 5.0.0 to make project compatible with Android 12
By default, react-native-mapbox-gl runs on API 9.1.0, so it won't be compatible with API 31, by the looks of it.
We are also seeing this, but only after changing the compileSdkVersion to 31, from 30.
Yes this is causing the issue. And the fix for me was adding the following version of telemetry
implementation 'com.mapbox.mapboxsdk:mapbox-android-telemetry:6.1.0'
We are also seeing this, but only after changing the compileSdkVersion to 31, from 30.
Yes this is causing the issue. And the fix for me was adding the following version of telemetry
implementation 'com.mapbox.mapboxsdk:mapbox-android-telemetry:6.1.0'
I tried this and it did not work for me. Try running ./gradlew uA to uninstall all SDKs and see if it still works.
The only solution that worked for me was to upgrade the mapbox SDK to 9.7.1
@savv Since we have React Native > 0.60, based on docs, no further steps are needed,
I assume we hava to manually put this code in build.gradle?
If yes, do we need all this section or just the line with the SDK?

Thank you Chris! Aris
Instructions are here https://github.com/react-native-mapbox-gl/maps/blob/master/android/install.md
Yes, I took the above code from there.
I was asking if we need to add the entire block or just the line for 9.7.1, since React Native>0.60 already takes care of the rest (in lower versions though).
Thanks.
I think you need all of them, otherwise it won't compile. But I don't know for sure.
Thanks a lot Chris! That's what I thought also and put all of them, I hope they will not cause other problems.
For example, when the package is updated, at some point we have to remove them! How would we know? We won't, something will break eventually in the future due to the usage of "non-defaults" and we will have to remember that we did some manual installation some time 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.
As I see it, a fix for new users wanting to run on Android 12 would be to explicitly pin the Mapbox telemetry SDK version in build.gradle as commented here:
We are also seeing this, but only after changing the compileSdkVersion to 31, from 30.
Yes this is causing the issue. And the fix for me was adding the following version of telemetry
implementation 'com.mapbox.mapboxsdk:mapbox-android-telemetry:6.1.0'
I'd be happy to provide a simple PR if that is useful, but I don't have a good enough overview to judge whether this is a fix rather than a workaround and whether this could cause problems in other areas I'm not familiar with.
It will be closed if no further activity occurs. Thank you for your contributions.
@stalebot I am very sad my activity is not good enough for you. :(