react-native-image-picker: [🐛] When select any image crash app
How to repeat issue and example
1.- Lauch method launchImageLibrary 2.- Select any image 3.- Confirm & crash
Solution
What needs to be done to address this issue? No crash app when select any image.
Additional Information
FATAL EXCEPTION: main
Process: com.copymaster, PID: 7518
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=13002, result=-1, data=Intent { flg=0x1 hwFlg=0x10 (has extras) }} to activity {com.copymaster/com.copymaster.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getLastPathSegment()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:5471)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5512)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getLastPathSegment()' on a null object reference
at com.imagepicker.Utils.getResponseMap(Utils.java:330)
at com.imagepicker.ImagePickerModule.onImageObtained(ImagePickerModule.java:145)
at com.imagepicker.ImagePickerModule.onActivityResult(ImagePickerModule.java:176)
at com.facebook.react.bridge.ReactContext.onActivityResult(ReactContext.java:308)
at com.facebook.react.ReactInstanceManager.onActivityResult(ReactInstanceManager.java:758)
at com.facebook.react.ReactDelegate.onActivityResult(ReactDelegate.java:90)
at com.facebook.react.ReactActivityDelegate.onActivityResult(ReactActivityDelegate.java:112)
at com.facebook.react.ReactActivity.onActivityResult(ReactActivity.java:68)
at android.app.Activity.dispatchActivityResult(Activity.java:8413)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5464)
... 11 more
Environment: “react”: “16.13.1”, “react-native”: “0.63.3”, “react-native-image-picker”: “^3.3.2”,
Phone Test:
- Huawei
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 10
- Comments: 27 (1 by maintainers)
It may be obvious but be sure your button handle double taps. It’s ease to reproduce this issue double tapping the button. With android, native modules can be mounted many times, it’s not the case with iOS. Maybe your customers tap the button, the native modal take to many time to show and clicked again. Or maybe your UI is not good enough and the “is tapping” state is not very clear for the user.
Issue still unresolved.
Per my comment above, it was actually double-tapping the button to open the image library that was causing the issue (@ludovicj44 was right on).
There are many ways to resolve this but I did so by adding a property on the button’s local state:
isDisabledAfterFirstPressand then after the first press it sets this to true. In my case, the button unmounts after press as well which is important otherwise the button could get into a stuck state.Hope this helps.
Having the same problem here. App crashes when I select the picture on Android.
Any workaround ?
@Maddumage @Dem0n13 try to recheck
WRITE_EXTERNAL_STORAGEpermission? in my project is use"react-native-permissions": "^2.2.2"to checkWRITE_EXTERNAL_STORAGEpermission. follow is my select image code:Hope useful
The same issue:
As I investigated: any android versions (7-10), any vendors. It comes from the next call:
My idea is the cause of problem is null returning from getAppSpecificStorageUri. Here are some examples of ResultInfo’s from Crash reports:
It’s strange to see this reports from “result=-1”. Note that I’ve already throttle button clicks by 1 second (I tried to prevent button multiclicking). Hope that it will be useful. Note 2 that this report come from Firebase Crashlytics.
Similar issue is occurring with Redmi phones also.
This happens for me too. Here is the Stack Trace from Sentry:
Here is the breadcrumbs…
Here is the distribution of the devices and other details. Of course, this issue only occurs on Android devices of every model. You can see that we have over 55 unique devices which have faced this issue @ravirajn22