maps icon indicating copy to clipboard operation
maps copied to clipboard

MapboxGL.setTelemetryEnabled(boolean) crashes on android

Open olofho opened this issue 5 years ago • 13 comments

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):

  • 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

olofho avatar Feb 21 '21 13:02 olofho

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.

airburst avatar Mar 09 '21 15:03 airburst

@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

ferdicus avatar Mar 12 '21 13:03 ferdicus

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!

olofho avatar Mar 12 '21 19:03 olofho

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.

airburst avatar Mar 12 '21 21:03 airburst

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.

stale[bot] avatar Jun 02 '21 16:06 stale[bot]

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?

Micgaw avatar Dec 06 '21 06:12 Micgaw

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

afilp avatar Jan 28 '22 11:01 afilp

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.

stanjhae avatar Mar 10 '22 22:03 stanjhae

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

jhu7235 avatar Mar 24 '22 00:03 jhu7235

Also getting this error using useEffect

Tim4497 avatar Apr 21 '22 11:04 Tim4497

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

thomasgrivet avatar Jun 15 '22 17:06 thomasgrivet

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

HeavenMin avatar Aug 03 '22 08:08 HeavenMin

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

Dantalion avatar Aug 30 '22 08:08 Dantalion