Describe the bug
See title.
Issue details
This happens both in debug and release mode.
Error Log
D/FilePickerDelegate(11781): Typeimage/*
D/FilePickerDelegate(11781): Typenull
D/AndroidRuntime(11781): Shutting down VM
E/AndroidRuntime(11781): FATAL EXCEPTION: main
E/AndroidRuntime(11781): Process: com.example, PID: 11781
E/AndroidRuntime(11781): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
E/AndroidRuntime(11781): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contains(java.lang.CharSequence)' on a null object reference
E/AndroidRuntime(11781): at com.mr.flutter.plugin.filepicker.FilePickerDelegate.startFileExplorer(FilePickerDelegate.java:166)
E/AndroidRuntime(11781): at com.mr.flutter.plugin.filepicker.FilePickerDelegate.onRequestPermissionsResult(FilePickerDelegate.java:134)
E/AndroidRuntime(11781): at io.flutter.embedding.engine.FlutterEnginePluginRegistry$FlutterEngineActivityPluginBinding.onRequestPermissionsResult(FlutterEnginePluginRegistry.java:612)
E/AndroidRuntime(11781): at io.flutter.embedding.engine.FlutterEnginePluginRegistry.onRequestPermissionsResult(FlutterEnginePluginRegistry.java:356)
E/AndroidRuntime(11781): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onRequestPermissionsResult(FlutterActivityAndFragmentDelegate.java:509)
E/AndroidRuntime(11781): at io.flutter.embedding.android.FlutterActivity.onRequestPermissionsResult(FlutterActivity.java:611)
E/AndroidRuntime(11781): at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:8264)
E/AndroidRuntime(11781): at android.app.Activity.dispatchActivityResult(Activity.java:8114)
E/AndroidRuntime(11781): at android.app.ActivityThread.deliverResults(ActivityThread.java:4839)
E/AndroidRuntime(11781): ... 11 more
I/Process (11781): Sending signal. PID: 11781 SIG: 9
Lost connection to device.
Exited (sigterm)
Source code (probably) involved: https://github.com/miguelpruivo/flutter_file_picker/blob/8f54c4fd4c17143e63caf1fa3e78d6558d9e7cf8/android/src/main/java/com/mr/flutter/plugin/filepicker/FilePickerDelegate.java#L154-L180
Flutter Version details
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.4 19E287, locale en-GB)
• Flutter version 1.12.13+hotfix.9 at /Users/***/Library/flutter
• Framework revision f139b11009 (5 weeks ago), 2020-03-30 13:57:30 -0700
• Engine revision af51afceb8
• Dart version 2.7.2
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/***/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
✗ Android license status unknown.
Try re-installing or updating your Android SDK Manager.
See https://developer.android.com/studio/#downloads or visit https://flutter.dev/setup/#android-setup for detailed instructions.
[✗] Xcode - develop for iOS and macOS
✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install:
sudo gem install cocoapods
[!] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[!] IntelliJ IDEA Community Edition (version 2019.3.4)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• For information about installing plugins, see
https://flutter.dev/intellij-setup/#installing-the-plugins
[✓] VS Code (version 1.44.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.10.1
[✓] Connected device (1 available)
• Mi A2 • 3fac5af • android-arm64 • Android 10 (API 29)
! Doctor found issues in 4 categories.
How are you picking it in your app?
So basically you are only using FileType.image? Could you provide the steps and emulator specs where you can _always_ reproduce this?
For simplicity my code to pick the image is:
final file = await FilePicker.getFile(type: FileType.image);
print(file.statSync());
Could you provide the steps and emulator specs where you can always reproduce this?
I'm working with a real device (Mi A2), I can try with a different one (emulated), ok?
I can always reproduce the bug disistalling the application every time or setting the storage permission to "denied".
I'm also facing the same issue. The application crashes the first time when plugin ask media permission. In my case I'm trying to upload images and pdf from user media.
This is also happening with Pixel 2 API 29 emulator.
D/FilePickerDelegate(17281): Typenull
D/AndroidRuntime(17281): Shutting down VM
E/AndroidRuntime(17281): FATAL EXCEPTION: main
E/AndroidRuntime(17281): Process: com.example, PID: 17281
E/AndroidRuntime(17281): java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=64450, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.example.my_quiz/com.example.my_quiz.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contains(java.lang.CharSequence)' on a null object reference
E/AndroidRuntime(17281): at android.app.ActivityThread.deliverResults(ActivityThread.java:4845)
E/AndroidRuntime(17281): at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)
E/AndroidRuntime(17281): at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
E/AndroidRuntime(17281): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime(17281): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime(17281): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
E/AndroidRuntime(17281): at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(17281): at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(17281): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime(17281): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17281): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime(17281): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/AndroidRuntime(17281): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contains(java.lang.CharSequence)' on a null object reference
E/AndroidRuntime(17281): at com.mr.flutter.plugin.filepicker.FilePickerDelegate.startFileExplorer(FilePickerDelegate.java:166)
E/AndroidRuntime(17281): at com.mr.flutter.plugin.filepicker.FilePickerDelegate.onRequestPermissionsResult(FilePickerDelegate.java:134)
E/AndroidRuntime(17281): at io.flutter.embedding.engine.FlutterEnginePluginRegistry$FlutterEngineActivityPluginBinding.onRequestPermissionsResult(FlutterEnginePluginRegistry.java:612)
E/AndroidRuntime(17281): at io.flutter.embedding.engine.FlutterEnginePluginRegistry.onRequestPermissionsResult(FlutterEnginePluginRegistry.java:356)
E/AndroidRuntime(17281): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onRequestPermissionsResult(FlutterActivityAndFragmentDelegate.java:509)
E/AndroidRuntime(17281): at io.flutter.embedding.android.FlutterActivity.onRequestPermissionsResult(FlutterActivity.java:611)
E/AndroidRuntime(17281): at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:8264)
E/AndroidRuntime(17281): at android.app.Activity.dispatchActivityResult(Activity.java:8114)
E/AndroidRuntime(17281): at android.app.ActivityThread.deliverResults(ActivityThread.java:4838)
E/AndroidRuntime(17281): ... 11 more
I/Process (17281): Sending signal. PID: 17281 SIG: 9
Lost connection to device.
Exited (sigterm)
So, this only happens after denying the permission?
So, this only happens after denying the permission?
No, sorry if I was not clear; this is happening every time the application request the permission using the system dialog and the user allow it (denying don't trigger the problem). However if the storage permission is already granted the plugin works correctly.
To trigger the problem I just go in the application settings and set the storage permission to denied.
Ok, we'll try to replicate and solve it with Pixel 2 API 29 emulator asap — expect to have the time for it later today.
Ok, just replicated the issue — only could reproduced it with Kotlin projects, Java seems to be fine.
I'm looking into it. Expecting a fix yet today.
Ok, FYI, found the culprit which is due to a Flutter issue, particularly related with #49365 and also this.
Basically, there's a known issue where the plugin might register the activity twice leading to this undesired side effects, such as triggering onRequestPermissionsResult twice.
Updating Flutter to any version above 1.14.6 will fix it right away (Flutter beta or dev or master channels). If you are on stable you will still have this issue until a new version has landed, which is due to be made yet this month (I believe they have plans for it in this or next week).
However, in the meantime, and because there's no way around, on 1.9.0+1 I've just added a null protection to it where the crash takes place, where otherwise shouldn't be required at all. I've commented it out so it can be removed along with this which is needed for the same reason from #210.
Please, update and clean your projects, and let me know if it worked for you.
Thanks!
@riccardoratta does that solve it for you now?
Yes, now it works!