expo: expo-image-picker crashes on Android after image is picked SDK 44

Summary

When picking an image on a standalone build (EAS), the app will crash/restart. The issue can be replicated in Expo Go when viewing the Snack by enabling the Developer Options > Don’t keep activities’ option.

The docs mention that Android likes to kill background processes and suggests to use ImagePicker.getPendingResultAsync() but offers no example on how this should be implemented. I’ve tried to implement it in a useEffect hook, before/after the image picking but the result is always the same, a crashed app.

It’s also worth mentioning I’m using Android 12 on a Samsung Galaxy S20 FE and it used to work fine with version 10.0.4. Also tested and failing with an Android Emulator - Android 9.

Thanks in advance!

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 - 12

SDK Version (managed workflow only)

44

Environment

Doesn’t matter as the problem is reproducible in Snack but here’s my local info.

expo-env-info 1.0.2 environment info: System: OS: Linux 5.4 Ubuntu 20.04.4 LTS (Focal Fossa) Shell: 5.0.17 - /bin/bash Binaries: Node: 14.18.2 - ~/.nvm/versions/node/v14.18.2/bin/node npm: 8.5.4 - ~/.nvm/versions/node/v14.18.2/bin/npm 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 react-navigation: ^4.4.4 => 4.4.4 npmGlobalPackages: eas-cli: 0.48.0 expo-cli: 5.3.0 Expo Workflow: managed

Reproducible demo

https://snack.expo.dev/@redxlll/image-picker

The Snack uses the exact same example code from the docs. Please note: Although this Snack uses Expo SDK 43 and expo-image-picker 11.0.3, the issue remains with SDK 44 and expo-image-picker 12.0.1.

About this issue

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

Commits related to this issue

Most upvoted comments

I’m also seeing this in my standalone build (expo 48.0.20, expo-image-picker 14.1.1, expo-image-loader 4.1.1). The app crashes on my android test device while interacting with the media library.

Failure delivering result ResultInfo{who=null, request=186834875, result=204, data=Intent { (has extras) }} to activity {com.xxx.xxx.xxx/com.xxx.xxx.xxx.MainActivity}: java.lang.IllegalArgumentException: Required value was null.

Installing expo-image-loader and rebuilding the app didn’t fix the issue.

I’m not sure why it’s necessary, I guess expo-image-picker should have a dependency on it but you should be able to fix it with:

npm install expo-image-loader

I’m not sure why it’s necessary, I guess expo-image-picker should have a dependency on it but you should be able to fix it with:

npm install expo-image-loader

Thanks for the suggestion will try it out later today, for now, I used a hacky way with DocumentPicker, yeah so anybody wondering if there is any workaround in a limited way you can use the DocumentPicker like so

result = await DocumentPicker.getDocumentAsync({
      type: ['image/*', 'video/*', 'application/x-mpegURL'],
      copyToCacheDirectory: true
    });

And then you can handle the cancel event and the processing of the picked media files. It works for me just fine. Although I’m still contemplating the fact that it seems like both of them are some kind of Native File Pickers yet only one gives you the desired outcome for now.

Also, I had one question is there a way in Expo either using Image Picker or any other expo package to let user pic pictures directly from camera roll like from the gallery app or something like that, for example in Instagram if you want to choose picture it either creates it’s own modal to display all your albums and camera roll itself, or there is a way to do it with expo package?