expo: Expo ImagePicker fails to launch. Call to function 'ExponentImagePicker.launchCameraAsync' has been rejected.
Summary
My users on Android arrive at a point where they can no longer launch the camera. User has given camera and media library permissions. User was able to open camera. User is no longer able to open Camera or Media Library.
It seems to be related to the expo task manager too.
** I’ve found that the issue appears when: **
- Given you are tracking location via a task in the task manager
- When you close the app
- When you reopen the app
- When you try to pick an image
- Then the image picker will not open
I’ve found that the issue does not appear when location tracking is not active when the app was last closed.
Check the linked repo with reproducible example.
result = await ImagePicker.launchCameraAsync({
base64: true,
allowsEditing: true,
mediaTypes: ImagePicker.MediaTypeOptions.Images,
quality: 0.2
});
// or
result = await ImagePicker.launchImageLibraryAsync({...})
Resulting error logs (source Sentry):
Error: Error: Call to function 'ExponentImagePicker.launchCameraAsync' has been rejected.
→ Caused by: java.lang.IllegalStateException: Attempting to launch an unregistered ActivityResultLauncher with contract expo.modules.imagepicker.contracts.CameraContra...
at ? (app:///index.android.bundle:3411:1320)
at generatorResume([native code])
at n(app:///index.android.bundle:269:69)
at p(app:///index.android.bundle:269:316)
at u(app:///index.android.bundle:2634:157)
at ? (app:///index.android.bundle:2634:884)
at ? (app:///index.android.bundle:76:1692)
at p(app:///index.android.bundle:76:528)
at N(app:///index.android.bundle:76:918)
at callReactNativeMicrotasks(app:///index.android.bundle:76:3079)
at value(app:///index.android.bundle:56:2935)
at ? (app:///index.android.bundle:56:1045)
at value(app:///index.android.bundle:56:2583)
at value(app:///index.android.bundle:56:1004)
at value([native code])
at value([native code])
Closing and reopening the app does not resolve the issue. Once a user has met this error, only reinstalling the app works.
What platform(s) does this occur on?
Android
Environment
expo-env-info 1.0.5 environment info: System: OS: macOS 12.0.1 Shell: 3.2.57 - /bin/bash Binaries: Node: 16.12.0 - ~/.nvm/versions/node/v16.12.0/bin/node Yarn: 1.22.17 - /usr/local/bin/yarn npm: 8.1.0 - ~/.nvm/versions/node/v16.12.0/bin/npm Watchman: 2021.06.07.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5 IDEs: Android Studio: 4.1 AI-201.8743.12.41.7199119 Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild npmPackages: expo: ^46.0.0 => 46.0.9 react: 18.0.0 => 18.0.0 react-dom: 18.0.0 => 18.0.0 react-native: 0.69.6 => 0.69.6 react-native-web: ~0.18.7 => 0.18.8 react-navigation: ^4.4.4 => 4.4.4 npmGlobalPackages: eas-cli: 0.53.1 expo-cli: 6.0.6 Expo Workflow: managed
Minimal reproducible example
The error appears only for production builds and dev builds using a dev-client.
I’ve been able to reproduce it via the example demo app in this github repository: https://github.com/Nxtra/expo-image-picker-issue-reproduce
The steps to reproduce the exact issue are in the repo, also here:
- run
npx expo start - open via dev client
- Press “pick an image”
- You will be able to pick an image
- Select start tracking
- After a few sec an icon will appear in you top notification bar indicating that you are being tracked
- Close the app (really close it by swiping it out of your open apps menu)
- Open app
- Press “pick an image”
- The camera picker won’t open!
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 18
- Comments: 98 (8 by maintainers)
Commits related to this issue
- fix attempt #1: add patches 2023-01-03 from https://github.com/expo/expo/issues/19512#issuecomment-1618927036 — committed to letam/expo-image-picker-issue-reproduce by letam 10 months ago
- fix attempt #2: Update patches 2023-07-03 from https://github.com/expo/expo/issues/19512#issuecomment-1618927036 — committed to letam/expo-image-picker-issue-reproduce by letam 10 months ago
- Patches for fixing https://github.com/expo/expo/issues/19512 — committed to appjusto/courier-app by pdandradeb 9 months ago
- [core][Android] Fix activity contract registration after host destruction (#26881) # Why Fixed https://github.com/expo/expo/issues/19512. # How When the host is destroyed and the app isn't k... — committed to expo/expo by lukmccall 5 months ago
Some news?
I have the same problem and the same steps to replicate it.
@Nxtra @bradjones1 @rgonzalez-clicoh @russnes @stharvey I was able to temporarily fix this in my app until the expo team can provide a permanent solution. I had to patch expo-image-picker using https://github.com/ds300/patch-package This is the patchfile for the version in the reproduction repo:
expo-image-picker+13.3.1.patchThis is the patchfile I for the most recent expo-image-picker version:
expo-image-picker+14.0.2.patchThe general idea is to repeat the registering and restart launching the picker in case it fails due to the here mentioned error.
I am not an android expert and only briefly tested it. So test it properly for yourself before using it.
I am running into this as well, however the error is on the image picker, not the camera:
Call to function 'ExponentImagePicker.launchImageLibraryAsync' has been rejected. → Caused by: java.lang.IllegalStateException: Attempting to launch an unregistered ActivityResultLauncher with contract expo.modules.imagepicker.contracts.ImageLibraryContract@7b3ffcc and input ImageLibraryContractOptions(options=expo.modules.imagepicker.ImagePickerOptions@fbf9cf1). You must ensure the ActivityResultLauncher is registered before calling launch()Unlike the OP, I do not engage in background location tracking. I do make calls to fetch location and they might be underway while the user is attempting to pick a photo. Perhaps that’s enough to trigger this?
I updated my patches for expo sdk 49. I did not have the time to completely test everything yet. So check yourself if it is working before using them.
For expo sdk 49 you need to apply 2 patch files. One is equal to the patch file from above. And the other one is reenabling an old api that was removed, even though the new one apparently does not work reliably as this issue seems to show.
@lukmccall You seem to have removed the public facing old api
registerForActivityResultin this pr while lots have people here in this thread experience issues with the image picker module not working with the new implementation. Would be nice if you guys could have a look at this issue.expo-image-picker+14.3.0.patch
expo-modules-core+1.5.3.patch
Happened in expo 49 also
I’m also experiencing the same issue, although I haven’t been as thorough in reproducing it in these steps. Now after deleting the app and reinstalling from Google Play, it appears to work. Testing on a galaxy S9, with versions:
I found a dirty workaround.
I am wrapping the call to `ImagePicker.launchCameraAsync’ in a try-catch block. If this specific error occurs, “Call to function ‘ExponentImagePicker.launchCameraAsync’ has been rejected”, then I suggest to restart the app in an alert:
Still painfull for the user, but less…
UPDATE: I’ve added a git repo with an example and steps to reproduce.
I encountered this issue for a while and couldn’t resolve it, despite trying all the solutions mentioned above. I even updated Expo from version 48 to 49, but the problem persisted. However, I eventually found a solution. It turns out that you no longer need to request permission. The Expo team has documented this in their official documentation, but I missed it initially. When I removed the code that requests permission before calling
launchImageLibraryAsyncin my code, the issue was completely resolved. I’m no longer getting any errors from Sentry.Still facing the error expo - 49.0.16 expo-image-picker - “~14.5.0”
Patches not working. Please help resolve this.
I’m getting
Call to function 'ExponentImagePicker.launchCameraAsync' has been rejected.when restarting my app and trying to take a picture. It happens on .apk after building with EAS, even though taking pictures after restarting works okay when the app is ran locally withnpx expo start."expo": "^49.0.10","expo-image-picker": "^14.5.0"I’ve got a smilar problem, but i am not using location tracking.
I am using: “expo-image-picker”: “~14.1.1”,
The problem is just opening the camera on android. Media library works fine. On IOS camera and library works fine.
WARN Possible Unhandled Promise Rejection (id: 0): Error: Call to function ‘ExponentImagePicker.launchCameraAsync’ has been rejected. → Caused by: java.lang.NullPointerException: Parameter specified as non-null is null: method host.exp.exponent.experience.d.checkSelfPermission, parameter permission.
Applying the patch for 14.0.2 doesn’t work. The code it 14.1.1 doesn’t seem to be the same.
the status prints: “granted”, it crashes somewhere around using launchCameraAsync
Edit: Even downgrading expo-image-picker to 12.0.1 (the last working version which i know for me) doesn’t work anymore, impossible to open the camera.
@TyAzur I encountered the same issue, but I managed to resolve it. Here are the steps I followed:
I applied two patches:
./patches/expo-image-picker+14.3.2.patchand./patches/expo-modules-core+1.5.9.patch, while using Expo SDK 49. Here is the code for those files: https://github.com/expo/expo/issues/19512#issuecomment-1697107235First, run
yarn installornpm installto ensure all dependencies are up to date.Then, execute
npx patch-packageto apply the patches or add"postinstall": "patch-package",to package.json and make sure you run it.After completing these steps, I was able to successfully build the project. Hope this helps!
We are also experiencing this problem: expo bare “expo”: “^47.0.0”, “react”: “18.1.0”, “react-native”: “0.70.9”, “expo-image-picker”: “~14.0.2”
Problem is very weird because occurs on client phone but not on mine (exactly same phones, Android versions…). A lot of our clients complains that can’t use camera in our app.
I’m also facing this issue on my app. It works fine on android emulator but I’m receiving the same error message on my own device(Xiaomi 11T Pro).
“expo”: 48.0.9 “react”: “18.2.0”, “react-native”: “0.71.4”,
Hello, I’m also experiencing a similar issue with the Expo Development Client build using EAS Build. I’m encountering the following error:
In my case:
expo-image-pickerversion 14.3.2expo-image-picker+14.3.2.patchHas anyone found a solution or a workaround for this issue? Any help would be greatly appreciated.
@haciSeydaoglu I see the code sample in their docs for
launchImageLibraryAsync:what about
ImagePicker.launchCameraAsync({ … })? I’ve been running into this error without ever requesting the ImageLibrary perm, but I do callawait ImagePicker.requestCameraPermissionsAsync()before trying to launch the camera.better way to solve : use Intent to choose Image on Android, only use Expo on iOS =)
@chanphiromsok Hi, which part of that stackoverflow helped you? it’s about SDK46 and SDK48. Thanks!
@mcottingham I think the reason is that I’m actually getting another similar error, which I documented in https://github.com/expo/expo/issues/24172.
So, the patch should work for those who have problems with
.launchCameraAsyncI can confirm it’s happening on SDK 49
“expo-image-picker”: “~14.3.2”,
I’m on SDK 49 and we still see this issue, I’ve seen it happening in both de dev build and the actual prod build (android). Haven’t tested on iOS tho. Is there anyone in the core team aware of this issue? Seems pretty critical as it can happen with both the camera and media picker
@johannessachse thanks, i’ve edited my comment
You need to delete your node modules. Make sure that on reinstall the patch-packages gives a success message. Then you need to recompile your app. Best is to delete the android folder as well to force a fresh build.
@green-munkey @DeltaPy , For you is it also related to having location services on at the same time? Then close the app, reopen and the problem appears.
Or what is the flow when you get this error?
I tried using the patch, but issue exists. Here is my patch file,
Can someone help me with a solution?
I’m also facing this issue on my app on android (RedMi note12)
We recently upgraded to expo 47 in production and this issue started popping up in Sentry. Background geotracking and camera are core features of our application. Did anyone find a workaround without the need to patch packages?
Watching with interest as I have experienced the same issue on a Pixel 4 device. Location Services and ImagePicker are core features of my app so it would be great to see a resolution.
I know I’m adding nothing new here but just wanted to add a message in case it helped to gauge the “breadth of impact”.
Thanks