question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
joebarrerocommented, Oct 16, 2022

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.

0reactions
mayromyllercommented, Oct 6, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's causing Expo's ImagePicker.launchCameraAsync() to ...
... occuring after taking a picture. The crashing described in the question occurs immediately upon calling imagePicker's camera method.
Read more >
Camera causes app to crash on physical Android device with ...
My EAS app crashes after taking a photo on Android. ... { Camera } from 'expo-camera'; import * as ImagePicker from 'expo-image-picker'; ...
Read more >
How to use the expo-image-picker.launchCameraAsync ...
expo -image-picker. Provides access to the system's UI for selecting images and videos from the phone's library or taking a photo with the...
Read more >
What's causing Expo's ImagePicker.launchCameraAsync() to ...
Coding example for the question What's causing Expo's ImagePicker.launchCameraAsync() to crash the app on some android devices?-React Native.
Read more >
expo-image-picker | Yarn - Package Manager
Provides access to the system's UI for selecting images and videos from the phone's library or taking a photo with the camera. API...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found