Android App Crashing only on first run when requesting Camera, and Location Permissions (for bluetooth)

Hi All!

So the first time the app runs on Android the app requests access to the:

  1. Location
  2. Camera
  3. Bluetooth

For some reason, the app crashes after requesting camera access and never gets to bluetooth. When running the app on an internal development build it doesn’t display any error. On subsequent runs it works fine. It only crashes on the first run of the app.

Code below:
//location/bluetooth
useEffect(() => {

(async () => {

  if (Platform.OS === "android") {

    let { status } = await Location.requestForegroundPermissionsAsync();

    if (status !== "granted") {

      console.log(status);

      setErrorMsg("Permission to access location was denied");

      return;

    }

    let location = await Location.getCurrentPositionAsync({});

    setLocation(location);

    console.log(location);

     status = await requestMultiple([

      PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION,

      PERMISSIONS.ANDROID.BLUETOOTH_SCAN,

      PERMISSIONS.ANDROID.BLUETOOTH_CONNECT,

      PERMISSIONS.ANDROID.BLUETOOTH_ADVERTISE,

    ]);

    if (

      status[PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION] === 'granted' &&

      ['granted', 'unavailable'].includes(

        status[PERMISSIONS.ANDROID.BLUETOOTH_CONNECT],

      ) &&

      ['granted', 'unavailable'].includes(

        status[PERMISSIONS.ANDROID.BLUETOOTH_SCAN],

      ) &&

      ['granted', 'unavailable'].includes(

        status[PERMISSIONS.ANDROID.BLUETOOTH_ADVERTISE],

      )

    ) {

     

    }

  }

})();

}, );

//camera permission
useEffect(() => {

(async () => {

  console.log("camera granted");

  const { status } = await Camera.requestCameraPermissionsAsync();

  setHasPermission(status === "granted");

  console.log("camera granted");

})();

}, [image]);

Thank you!

Hi @accountableapp

Could you let us know what error you get when it crashes? If this is a native crash you might need to use adb logcat to get the details.

Someone else mentioned a “crash on first run” issue as well. In their case it is caused by an Illegal instruction signal and there’s already a React Native issue for it. So maybe you’re running into the same problem:

If your issue is the same and you have more details (e.g. it only happens when requesting access to the camera, or only on a certain Android version or on certain devices, etc.) then add that info to the issue.

I figured this out! I needed to request the camera first, let it load, and then request location permission. Having them run in tandem was causing the app to crash for some reason.

Weird. Still seems like a bug.

If you can get the logcat output it is probably worth adding to the issue I mentioned (if it’s the same) or creating a new issue with the details.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.