expo: [expo-image-picker] Crash when trying to call launchCameraAsync to get an image

Summary

The application crashes when I introduce expo-image-picker and call launchCameraAsync as specified in the documentation.

The camera starts immediately after calling launchCameraAsync. Then the application crashes when I take a picture with the camera and select the image. So it works fine until the camera is launched, but crashes when it tries to acquire an image.

As per this issue, if I go back without taking a photo after launching the camera once and then launch the camera again to take a photo, I may be able to get it.

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

44

Environment

expo-env-info 1.0.3 environment info: System: OS: Linux 5.10 Debian GNU/Linux 10 (buster) 10 (buster) Shell: 3.0.2 - /usr/bin/fish Binaries: Node: 16.13.1 - /tmp/yarn–1651720947618-0.5496521237718734/node Yarn: 1.22.17 - /tmp/yarn–1651720947618-0.5496521237718734/yarn npm: 8.1.2 - /usr/local/bin/npm IDEs: Android Studio: AI-211.7628.21.2111.8193401 npmPackages: expo: ~44.0.0 => 44.0.6 react: 17.0.1 => 17.0.1 react-dom: 17.0.1 => 17.0.1 react-native: 0.64.3 => 0.64.3 react-native-web: 0.17.1 => 0.17.1 Expo Workflow: managed

Reproducible demo

https://github.com/chimame/react-native-camera-crash-sample

I submit the code for the crashing sample I created. It crashes both when using Expo Go and when built with EAS.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

Please try this:

Comment on the part that asks for permission. When we only use ImagePicker.launchCameraAsync it already requests permission. I did this and managed to fix it 100%.

async function pickImageFromCamera() {
    // const { granted } = await ImagePicker.requestCameraPermissionsAsync()

    // if (granted) {
      const result = await ImagePicker.launchCameraAsync({
        mediaTypes: ImagePicker.MediaTypeOptions.Images,
        aspect: [4, 3],
        base64: true,
        quality: 0.5
      })
    // }
  }

For more details: https://forums.expo.dev/t/issues-on-getting-imagepicker-launchcameraasync-to-work/71100/9

I have the same problem on all the devices I tried, both ios and android. When I try to open the gallery, I get the following error: Cannot read property ‘launchImageLibraryAsync’ of undefined . I tried with other methods of the package and it is the same situation. I can only access hooks and enums from ImagePicker

Expo Sdk: 47 expo-image-picker:14.0.2

Has anyone found a solution??

We’re having this issue on a Realme 8 5G, our application crashes after taking a picture

Hello everyone, I had the same problem, in several Samsung devices, in addition to several other devices as well.

I ended up finding a solution, which took the permissions directly from the React Native package and implemented it in my app, and to my surprise and relief, it worked perfectly, both running through the expo and also after the build. Following example code:

import { PermissionsAndroid } from "react-native"

async function pickImageFromCamera() {
  const granted = await PermissionsAndroid.request(
    PermissionsAndroid.PERMISSIONS.CAMERA
  )

  if (granted === PermissionsAndroid.RESULTS.GRANTED) {
    setOpenCamera(true)

    const result = await ImagePicker.launchCameraAsync({
      mediaTypes: ImagePicker.MediaTypeOptions.Images,
      aspect: [4, 3],
      base64: true,
      quality: 1
    })

    if (!result.cancelled) {
     // your logic
    }
  }
}

Hope this helps.

Adding a different permissions request didn’t help me. I’m experiencing the same error after ensuring that I have the permissions.