Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image_picker Bitmap NullPointException on Android 10 with open failed: EACCES (Permission denied) #41459

Closed
mofada opened this issue Sep 27, 2019 · 88 comments
Assignees
Labels
a: images Loading, displaying, rendering images c: crash Stack traces logged to the console c: regression It was better in the past than it is now customer: money (g3) customer: quill (g3) e: OS-version specific Affects only some versions of the relevant operating system p: image_picker The Image Picker plugin. package flutter/packages repository. See also p: labels. platform-android Android applications specifically

Comments

@mofada
Copy link

mofada commented Sep 27, 2019

When I made a picture selection on Xiaomi Mi 9, I got an error. I debugged it and found that getting the bitmap failed. I got it on another phone Pixel 3 XL.

BitmapFactory show message : EACCES (Permission denied)

However, the display details have been granted in the app details interface.

debug

bitmapFactory

screen

Logs

W/99.bole_studen: Got a deoptimization request on un-deoptimizable method java.io.FileDescriptor libcore.io.Linux.open(java.lang.String, int, int)
W/System.err: java.io.FileNotFoundException: /storage/emulated/0/DCIM/Screenshots/Screenshot_2019-09-26-18-58-07-298_com.tencent.mobileqq.jpg: open failed: EACCES (Permission denied)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:496)
W/System.err:     at java.io.FileInputStream.<init>(FileInputStream.java:159)
W/System.err:     at java.io.FileInputStream.<init>(FileInputStream.java:115)
W/System.err:     at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:515)
W/System.err:     at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:542)
W/System.err:     at io.flutter.plugins.imagepicker.ImageResizer.resizedImage(ImageResizer.java:51)
W/System.err:     at io.flutter.plugins.imagepicker.ImageResizer.resizeImageIfNeeded(ImageResizer.java:40)
W/System.err:     at io.flutter.plugins.imagepicker.ImagePickerDelegate.handleImageResult(ImagePickerDelegate.java:530)
W/System.err:     at io.flutter.plugins.imagepicker.ImagePickerDelegate.handleChooseImageResult(ImagePickerDelegate.java:463)
W/System.err:     at io.flutter.plugins.imagepicker.ImagePickerDelegate.onActivityResult(ImagePickerDelegate.java:442)
W/System.err:     at io.flutter.app.FlutterPluginRegistry.onActivityResult(FlutterPluginRegistry.java:204)
W/System.err:     at io.flutter.app.FlutterActivityDelegate.onActivityResult(FlutterActivityDelegate.java:132)
W/System.err:     at io.flutter.app.FlutterActivity.onActivityResult(FlutterActivity.java:142)
        at android.app.Activity.dispatchActivityResult(Activity.java:8250)
W/System.err:     at android.app.ActivityThread.deliverResults(ActivityThread.java:4898)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4946)
W/System.err:     at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
W/System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:221)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7520)
        at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
W/System.err: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
        at libcore.io.Linux.open(Native Method)
W/System.err:     at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
        at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
W/System.err:     at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
        at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7419)
W/System.err:     at libcore.io.IoBridge.open(IoBridge.java:482)
    	... 25 more

flutter doctor -v

C:\Users\fada>flutter doctor -v
[√] Flutter (Channel master, v1.10.7-pre.51, on Microsoft Windows [Version 10.0.18362.356], locale zh-CN)
    • Flutter version 1.10.7-pre.51 at D:\flutter
    • Framework revision 957d839775 (3 hours ago), 2019-09-26 22:45:21 -0700
    • Engine revision a206557f8f
    • Dart version 2.6.0 (build 2.6.0-dev.3.0 327bc451f8)


[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at D:\Android\android-sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = D:\Android\android-sdk
    • Java binary at: D:\Android\android-studio canary\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
    • All Android licenses accepted.

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.2.5)
    • Visual Studio at D:\Program Files (x86)\Microsoft Visual Studio\Community
    • Visual Studio Community 2019 version 16.2.29306.81

[√] Android Studio (version 3.5)
    • Android Studio at D:\Android\android-studio
    • Flutter plugin version 39.0.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[!] Android Studio (version 3.6)
    • Android Studio at D:\Android\android-studio canary
    X Flutter plugin not installed; this adds Flutter specific functionality.
    • Dart plugin version 192.6262.58
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] IntelliJ IDEA Ultimate Edition (version 2019.2)
    • IntelliJ at D:\JetBrains\IntelliJ IDEA
    • Flutter plugin version 39.0.5
    • Dart plugin version 192.6603.23

[√] Connected device (2 available)
    • MI 9    • c3bd46f9 • android-arm64 • Android 10 (API 29)
    • Windows • Windows  • windows-x64   • Microsoft Windows [Version 10.0.18362.356]

! Doctor found issues in 1 category.
@mofada
Copy link
Author

mofada commented Sep 27, 2019

Supplementary log

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.dct99.bole_student, PID: 16255
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2342, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:339675 flg=0x1 }} to activity {com.dct99.bole_student/com.dct99.bole_student.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4905)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4946)
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:221)
        at android.app.ActivityThread.main(ActivityThread.java:7520)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
        at io.flutter.plugins.imagepicker.ImageResizer.resizedImage(ImageResizer.java:52)
        at io.flutter.plugins.imagepicker.ImageResizer.resizeImageIfNeeded(ImageResizer.java:40)
        at io.flutter.plugins.imagepicker.ImagePickerDelegate.handleImageResult(ImagePickerDelegate.java:530)
        at io.flutter.plugins.imagepicker.ImagePickerDelegate.handleChooseImageResult(ImagePickerDelegate.java:463)
        at io.flutter.plugins.imagepicker.ImagePickerDelegate.onActivityResult(ImagePickerDelegate.java:442)
        at io.flutter.app.FlutterPluginRegistry.onActivityResult(FlutterPluginRegistry.java:204)
        at io.flutter.app.FlutterActivityDelegate.onActivityResult(FlutterActivityDelegate.java:132)
        at io.flutter.app.FlutterActivity.onActivityResult(FlutterActivity.java:142)
        at android.app.Activity.dispatchActivityResult(Activity.java:8250)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4898)
        at android.app.ActivityThread.handleSendResult(ActivityThread.java:4946) 
        at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:221) 
        at android.app.ActivityThread.main(ActivityThread.java:7520) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) 

@escamoteur
Copy link
Contributor

Did you add the necessary permissions in your android project?

@escamoteur escamoteur added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 27, 2019
@mofada
Copy link
Author

mofada commented Sep 27, 2019

No, I didn't add it, image_picker implements the permission request internally.

image

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 27, 2019
@escamoteur
Copy link
Contributor

Does the exception happen when you tap on an image or even before?
Is the path really the correct one?

@escamoteur
Copy link
Contributor

Not sure if I understand it correctly does it Work on the Pixel or doesn't it work on any phone?
Which version of the image_picker are you using?

@mofada
Copy link
Author

mofada commented Sep 27, 2019

There is only an exception here, I think it may be because of the system, because the miui of the xiaomi released a new version these two days.
The path is correct, the file exists normally

@mofada
Copy link
Author

mofada commented Sep 27, 2019

image_picker: ^0.6.1+4

@mofada
Copy link
Author

mofada commented Sep 27, 2019

I am normal on the lower version of xiaomi's miui system, I am confused.

@escamoteur
Copy link
Contributor

It does work on the Google Pixel?

@mofada
Copy link
Author

mofada commented Sep 27, 2019

Yes, my phone is google pixel 3 xl, it works fine

@escamoteur escamoteur added e: device-specific Only manifests on certain devices p: image_picker The Image Picker plugin. c: crash Stack traces logged to the console platform-android Android applications specifically labels Sep 27, 2019
@escamoteur escamoteur changed the title image_picker Bitmap NullPointerException image_picker Bitmap NullPointerException on Xiomi Mi 9 Sep 27, 2019
@escamoteur
Copy link
Contributor

Which Android version runs on the Xiomi?

@mofada
Copy link
Author

mofada commented Sep 27, 2019

Android 10 and MIUI system 11

@mofada
Copy link
Author

mofada commented Sep 28, 2019

Now I can't choose on my pixel 3 xl.

@mofada
Copy link
Author

mofada commented Sep 28, 2019

Pixel 3 XL

E/BitmapFactory(27576): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/tencent/QQ_Images/0.jpg: open failed: EACCES (Permission denied)
D/AndroidRuntime(27576): Shutting down VM
E/AndroidRuntime(27576): FATAL EXCEPTION: main
E/AndroidRuntime(27576): Process: com.dct99.bole_student, PID: 27576
E/AndroidRuntime(27576): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2342, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:176513 flg=0x1 }} to activity {com.dct99.bole_student/com.dct99.bole_student.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
E/AndroidRuntime(27576): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:4845)
E/AndroidRuntime(27576): 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)
E/AndroidRuntime(27576): 	at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
E/AndroidRuntime(27576): 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime(27576): 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime(27576): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
E/AndroidRuntime(27576): 	at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(27576): 	at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(27576): 	at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime(27576): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(27576): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime(27576): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/AndroidRuntime(27576): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
E/AndroidRuntime(27576): 	at io.flutter.plugins.imagepicker.ImageResizer.resizedImage(ImageResizer.java:53)
E/AndroidRuntime(27576): 	at io.flutter.plugins.imagepicker.ImageResizer.resizeImageIfNeeded(ImageResizer.java:41)
E/AndroidRuntime(27576): 	at io.flutter.plugins.imagepicker.ImagePickerDelegate.handleImageResult(ImagePickerDelegate.java:530)
E/AndroidRuntime(27576): 	at io.flutter.plugins.imagepicker.ImagePickerDelegate.handleChooseImageResult(ImagePickerDelegate.java:463)
E/AndroidRuntime(27576): 	at io.flutter.plugins.imagepicker.ImagePickerDelegate.onActivityResult(ImagePickerDelegate.java:442)
E/AndroidRuntime(27576): 	at io.flutter.app.FlutterPluginRegistry.onActivityResult(FlutterPluginRegistry.java:204)
E/AndroidRuntime(27576): 	at io.flutter.app.FlutterActivityDelegate.onActivityResult(FlutterActivityDelegate.java:132)
E/AndroidRuntime(27576): 	at io.flutter.app.FlutterActivity.onActivityResult(FlutterActivity.java:142)
E/AndroidRuntime(27576): 	at android.app.Activity.dispatchActivityResult(Activity.java:8110)
E/AndroidRuntime(27576): 	at android.app.ActivityThread.deliverResults(ActivityThread.java:4838)
E/AndroidRuntime(27576): 	... 11 more
I/Process (27576): Sending signal. PID: 27576 SIG: 9
Lost connection to device.

@mofada
Copy link
Author

mofada commented Sep 28, 2019

[ro.product.board]: [crosshatch]
[ro.product.brand]: [google]
[ro.product.build.date]: [Wed Sep 11 22:36:39 UTC 2019]
[ro.product.build.date.utc]: [1568241399]
[ro.product.build.fingerprint]: [google/crosshatch/crosshatch:10/QP1A.190711.020.C3/5869620:user/release-keys]
[ro.product.build.id]: [QP1A.190711.020.C3]
[ro.product.build.tags]: [release-keys]
[ro.product.build.version.release]: [10]
[ro.product.build.version.sdk]: [29]
[ro.product.cpu.abi]: [arm64-v8a]
[ro.product.cpu.abilist]: [arm64-v8a,armeabi-v7a,armeabi]
[ro.product.cpu.abilist32]: [armeabi-v7a,armeabi]
[ro.product.cpu.abilist64]: [arm64-v8a]
[ro.product.device]: [crosshatch]
[ro.product.first_api_level]: [28]
[ro.product.locale]: [en-US]
[ro.product.model]: [Pixel 3 XL]
[ro.product.name]: [crosshatch]

@escamoteur
Copy link
Contributor

That is really strange. Before you could select on the Pixel?

@mofada
Copy link
Author

mofada commented Sep 28, 2019

image

@mofada
Copy link
Author

mofada commented Sep 28, 2019

I am pretty sure that the file exists.

@mofada
Copy link
Author

mofada commented Sep 28, 2019

I tried another xiaomi, Android version 7.1.1. He is normal. I am surprised that it was OK yesterday. I will not be able to uninstall and reinstall today.

@escamoteur
Copy link
Contributor

I think you use it the wrong way. pickImage returns a File you have to use this File to load the image because Android makes a copy for you that is later removed.

@mofada
Copy link
Author

mofada commented Sep 28, 2019

The problem now is that I have crashed without getting the image program.

@escamoteur
Copy link
Contributor

Did you get another error?

@mofada
Copy link
Author

mofada commented Sep 28, 2019

On this issue, the file crashes when it is selected. The reason is open failed: EACCES (Permission denied), but it is normal on the xiaomi phone that also requires the runtime permissions of 7.1.1, which is not normal on xiaomi 9 android 10. But yesterday I was normal on the pixel 3 xl of android 10, but today it is not working.

@alejandrorosas
Copy link

Happening the same when selecting a recent image using Pixel 4.

Adding the requestLegacyExternalStorage property fixes the issue for now.

@mockturtl
Copy link
Contributor

What are the model of devices that cause the issue in the original post(permission denial issue)?
What is the Android SDK version? (I have seen 29 is the version caused the problem but I want to confirm.)

emulator, Pixel C API 29

Meebuhs added a commit to Meebuhs/sendrax that referenced this issue Feb 1, 2020
@cyanglaz
Copy link
Contributor

Un-assign myself from this issue as I don't have cycle to actively working on it.

@cyanglaz cyanglaz removed their assignment Mar 12, 2020
@cyanglaz cyanglaz removed this from the Near-term Goals milestone Mar 12, 2020
@9thwall
Copy link

9thwall commented Mar 21, 2020

I'm using Pixel3 and @DevAlpesh fix solved the issue.

@zhaofengnju
Copy link

Ping... Is there any progress on this issue?

The workaround here to add requestLegacyExternalStorage doesn't work in Android 11:
"After you update your app to target Android 11, the system ignores the requestLegacyExternalStorage flag."
https://developer.android.com/preview/privacy/storage

It blocks our targeting to Android 11.
Thanks!

@cyanglaz
Copy link
Contributor

cyanglaz commented May 1, 2020

opened a WIP PR to fix this flutter/plugins#2728
I'm still working on the testing, but anyone wants to try apply the PR, you should see the fix.

@cyanglaz
Copy link
Contributor

cyanglaz commented May 5, 2020

Should be fixed by flutter/plugins#2728 in image_picker 0.6.6+1
I'm going to close the issue, please feel free to tag me on this issue if you still face the same problem after updating image_picker to 0.6.6+1; Or open a new GitHub issue if you found a different issue.

@cyanglaz cyanglaz closed this as completed May 5, 2020
@praharshbhatt
Copy link

@joknjokn look here
image

image

This works perfectly

@LiMengyang990726
Copy link

Hi team, using Android API level 29 (Android10).

Got this problem: After the permission has been granted (following request runtime permission), still got open failed: EACCES (Permission denied) when trying to read from the internal storage.

Is adding android:requestLegacyExternalStorage="true" in manifest.xml the only solution? <- As the solution looks like a temporary opt-out

@deborahjames
Copy link

[WORKED FOR ME]
ERROR : BitmapFactory: Unable to decode stream: /storage/emulated/filepath.jpg: open failed: EACCES (Permission denied)
SOLUTION : Thanks was able to solve the issue by adding android:requestLegacyExternalStorage="true" in AndroidMAnifest.xml file.

@kbrmimbyl
Copy link

This thread just saved my life. flutter 1.22.1, image_picker 0.6.3+1

@IbtsamRana
Copy link

Updating the image_picker version solved my issue

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: images Loading, displaying, rendering images c: crash Stack traces logged to the console c: regression It was better in the past than it is now customer: money (g3) customer: quill (g3) e: OS-version specific Affects only some versions of the relevant operating system p: image_picker The Image Picker plugin. package flutter/packages repository. See also p: labels. platform-android Android applications specifically
Projects
None yet
Development

No branches or pull requests