Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ANDROID] Mapbox.UserLocation crashes my app! #233

Closed
karlguillotte opened this issue Jul 10, 2019 · 19 comments
Closed

[ANDROID] Mapbox.UserLocation crashes my app! #233

karlguillotte opened this issue Jul 10, 2019 · 19 comments
Labels
wontfix This will not be worked on

Comments

@karlguillotte
Copy link
Contributor

Describe the bug
I wanted to give a try to the latest release candidate (want to upgrade to the new Mapbox pricing model). My app uses the new <UserLocation /> inside a <MapView />. My app crashes on launch. It does not crash if I remove the <UserLocation />.

I added and removed the permissions and features and it still crashes.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-feature android:name="android.hardware.location.gps"/>

To Reproduce
Create and render that component (simplified code):

function Map() {
  return (
    <MapView>
      <UserLocation />
    </MapView>
  )
}

Expected behavior
I would expected my app to run properly.

Versions:

  • Platfrom: Android
  • Device: ONE A2005
  • OS: 3.6.1
  • SDK Version: 28
  • React Native Version: 0.59.9

Additional context

Here is the log:
07-10 15:09:37.634 30607 30649 E AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
07-10 15:09:37.634 30607 30649 E AndroidRuntime: Process: com.avcan, PID: 30607
07-10 15:09:37.634 30607 30649 E AndroidRuntime: java.lang.SecurityException: "passive" location provider requires ACCESS_FINE_LOCATION permission.
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1620)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1573)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at android.location.ILocationManager$Stub$Proxy.getLastLocation(ILocationManager.java:738)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at android.location.LocationManager.getLastKnownLocation(LocationManager.java:1240)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at com.mapbox.android.core.location.AndroidLocationEngineImpl.getLastLocationFor(AndroidLocationEngineImpl.java:58)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at com.mapbox.android.core.location.MapboxFusedLocationEngineImpl.getBestLastLocation(MapboxFusedLocationEngineImpl.java:81)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at com.mapbox.android.core.location.MapboxFusedLocationEngineImpl.getLastLocation(MapboxFusedLocationEngineImpl.java:36)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at com.mapbox.android.core.location.LocationEngineProxy.getLastLocation(LocationEngineProxy.java:25)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at com.mapbox.rctmgl.location.LocationManager.getLastKnownLocation(LocationManager.java:125)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at com.mapbox.rctmgl.modules.RCTMGLLocationModule.getLastKnownLocation(RCTMGLLocationModule.java:88)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at android.os.Looper.loop(Looper.java:152)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
07-10 15:09:37.634 30607 30649 E AndroidRuntime: at java.lang.Thread.run(Thread.java:818)

@martinfrouin
Copy link

martinfrouin commented Jul 26, 2019

I've got the same issue on Android Only

Honor 8X
Android 9
RN 0.59.10

@winseyli
Copy link

winseyli commented Aug 1, 2019

Same here with <MapboxGL.UserLocation />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> exists.

SDK Version: 28
React Native Version: 0.59.9
Device: Android 8.0

@RichardLindhout
Copy link
Contributor

You need to explicitly ask access to permissions now

@martinfrouin
Copy link

@RichardLindhout yes since Android 4.4
But it's crashing before asking access to the permissions

@RichardLindhout
Copy link
Contributor

Do not render before you know it has a permission
{hasPermission && <Mapbox.UserLocation />}

@martinfrouin
Copy link

Yes, it's the fix I'm using actually, but it's not supposed to make my app crash

@segheysens
Copy link

@tinmar33 are you receiving the same errors as @karlguillotte mentioned above? Do you have any similar details about what you're seeing? (environment details, logs, etc)

@karlguillotte have you tried this recommendation of enforcing location permission before rendering the Mapbox.UserLocation context?

@karlguillotte
Copy link
Contributor Author

karlguillotte commented Aug 12, 2019

@segheysens I have not, I will. It is a different behavior then previous version and it should probably be documented. Thanks! I will keep you posted.

@martinfrouin
Copy link

@segheysens Yes, i get the same errors as him (same logs / environment)

@karlguillotte
Copy link
Contributor Author

karlguillotte commented Aug 13, 2019

I just gave it a try and using requestAndroidLocationPermissions fixed the problem.

Leaving it open because I think that difference between platforms should be documented.

@martinfrouin
Copy link

This fix seems better than mine (using React NativePermissionAndroid feature)
Thanks @karlguillotte

@RichardLindhout
Copy link
Contributor

RichardLindhout commented Aug 17, 2019

Some code snippets. Thanks @karlguillotte :-)

import { Platform } from 'react-native'
import Mapbox from '@react-native-mapbox-gl/maps'

export async function hasLocationPermission() {
  if (
    Platform.OS === 'web' ||
    Platform.OS === 'ios' ||
    (Platform.OS === 'android' && Platform.Version < 23)
  ) {
    return true
  }
  const isGranted = await Mapbox.requestAndroidLocationPermissions()

  console.log('isGranted', isGranted)
  return isGranted
}
const [permission, setPermission] = useState(false)
  useEffect(() => {
    const task = async () => {
      const per = await hasLocationPermission()
      setPermission(per)
    }
    task()
  }, [false])

@stale
Copy link

stale bot commented Oct 16, 2019

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 stale bot added the wontfix This will not be worked on label Oct 16, 2019
@stale stale bot closed this as completed Oct 23, 2019
@brunogonncalves
Copy link

Same problem here!

@pixelleaf
Copy link

Same issue, despite explicitly requesting permissions with const isGranted = await Mapbox.requestAndroidLocationPermissions();, and adding permissions to the android manifest. I followed the above example to a tee as well. Any advice or hints would be greatly appreciated!

@ferdicus
Copy link
Member

ferdicus commented Jan 22, 2020

@brandonreavis @ciphled, can you please make sure, that you're on current master instead of 7.0.9?

make sure to use this in your package.json

    "@react-native-mapbox-gl/maps": "git+https://github.com/react-native-mapbox-gl/maps.git#master",

@pixelleaf
Copy link

@ferdicus I can confirm that I'm using 7.0.9 and not the current master. I'll change the version to the current master and get back to you -- I'm adamant the instability is due to this. Thanks!

@pixelleaf
Copy link

@ferdicus It's generating gradle build errors, so I'll have to do a full rebuild from scratch tomorrow. Thanks again -- hopefully the latest update resolves the instability :).

@pixelleaf
Copy link

@ferdicus @brandonreavis I had stability issues with the latest build as well. What ultimately worked was downgrading to 7.0.8. I'll upgrade to 8.0.0^ once it's proven to be stable. Cheers for the effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

8 participants