React Native Expo app crashing on android apk file when ask location permission

Viewed 2532

I have problem with expo standalone app. the problem is with the ask permissions for locations. in the development mode, app asks for location permissions and works well. there is no bugs. after build the app using expo build:android, it creates a android standalone app. and after installing that APK and try to access the same page that asks for location permissions, the app is crashed and restarted.

  Expo CLI 4.7.3 environment info:
    System:
      OS: Windows 10 10.0.19042
    Binaries:
      Node: 14.15.4 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.10 - C:\Users\ISLAMSOFT\AppData\Roaming\npm\yarn.CMD
      npm: 7.6.3 - C:\Program Files\nodejs\npm.CMD
    IDEs:
      Android Studio: Version  4.2.0.0 AI-202.7660.26.42.7486908
    npmPackages:
      expo: ~40.0.0 => 40.0.1
      react: 16.13.1 => 16.13.1
      react-dom: 16.13.1 => 16.13.1
      react-native: https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz => 0.63.2
      react-native-web: ~0.13.12 => 0.13.18
    Expo Workflow: managed

in app.json I added this but not solve the problem

"android": {
      "permissions":[
        "ACCESS_COARSE_LOCATION",
        "ACCESS_FINE_LOCATION",
        "CAMERA",
        "READ_EXTERNAL_STORAGE",
        "WRITE_EXTERNAL_STORAGE"
      ]
    },

I don't know how to test the apk file to check the error

1 Answers

Possible reason 1


I had same problem in my expo app few days earlier. There I needed AUDIO_RECORDING permission for my app. The app was fine in development but crashing on the production.

I have found the I missed the await keyword befor taking the permission in useEffect. Something like this:

 useEffect(() => {
    Permissions.askAsync(Permissions.AUDIO_RECORDING)
 }, [])

Then I completely removed the above code. Then the permission was taken from an onPressIn event of a TouchableOpacity button. The code was something like this:

  const startRecording = async () => {
    const { status } = await Permissions.getAsync(Permissions.AUDIO_RECORDING);
    if (status !== 'granted') return;
    
    // Other codes...
  }

You should double check how you took your permission.

Possible reason 2


Sometimes the expo app crashed because of wrong css value like this:

{flex: '1'}

Instead of

{flex: 1}

This kind of small mistakes crashed my apps many times. You should check all of your css property values.

Related