FilePicker version is 2.0.6. flutter clean and flutter build didn't help.
Describe the bug
I can't select a directory on a phone with Android 8.1, or on emulator with Android 8.1. The same code works with Android 11.
My compileSdkVersion is 28, minSdkVersion is 21 and targetSdkVersion is 28.
Issue details
final String fromPath = await FilePicker.platform.getDirectoryPath();, but fromPath is null. No matter which directory I choose (I tried root directory, Downloads, created a test directory in the root, it doesn't matter).I've read Troubleshooting page, it says there are directories on Android which can't be picked manually, but what directory should I choose then, even if my freshly created directory doesn't work?
Error Log
Launching lib\main.dart on BV5800 in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Waiting for BV5800 to report its views...
Debug service listening on ws://127.0.0.1:59288/wBV95REH17s=/ws
Syncing files to device BV5800...
D/Surface ( 8429): Surface::disconnect(this=0x7635ff6000,api=1)
D/Surface ( 8429): Surface::disconnect(this=0x7635ff6000,api=-1)
D/Surface ( 8429): Surface::disconnect(this=0x7635ff5000,api=1)
V/PhoneWindow( 8429): DecorView setVisiblity: visibility = 4, Parent = ViewRoot{5a31781 com.example.hello_world/com.example.hello_world.MainActivity,ident = 0}, this = DecorView@68a9a8b[MainActivity]
I/zygote64( 8429): Do partial code cache collection, code=26KB, data=25KB
I/zygote64( 8429): After code cache collection, code=26KB, data=25KB
I/zygote64( 8429): Increasing code cache capacity to 128KB
D/FilePickerDelegate( 8429): [SingleFilePick] File URI:content://com.android.externalstorage.documents/tree/primary%3Atest/document/primary%3Atest
I/FilePickerUtils( 8429): Caching from URI: content://com.android.externalstorage.documents/tree/primary%3Atest/document/primary%3Atest
E/FilePickerUtils( 8429): Failed to retrieve path: read failed: EISDIR (Is a directory)
V/PhoneWindow( 8429): DecorView setVisiblity: visibility = 0, Parent = ViewRoot{5a31781 com.example.hello_world/com.example.hello_world.MainActivity,ident = 0}, this = DecorView@68a9a8b[MainActivity]
D/Surface ( 8429): Surface::connect(this=0x7635ff5000,api=1)
D/Surface ( 8429): Surface::connect(this=0x7635ff7000,api=1)
I/flutter ( 8429): [MethodChannelFilePicker] Could not resolve directory path. Maybe it's a protected one or unsupported (such as Downloads folder). If you are on Android, make sure that you are on SDK 21 or above.
Flutter Version details
C:\Users\Зарубкин>flutter doctor -v
[√] Flutter (Channel stable, 1.22.0, on Microsoft Windows [Version 10.0.14393], locale ru-RU)
• Flutter version 1.22.0 at C:\flutter
• Framework revision d408d302e2 (6 days ago), 2020-09-29 11:49:17 -0700
• Engine revision 5babba6c4d
• Dart version 2.10.0
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:\android-sdk
• Platform android-30, build-tools 30.0.2
• ANDROID_HOME = C:\android-sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] Android Studio (version 4.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 50.0.1
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] VS Code, 64-bit edition (version 1.49.2)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 3.14.1
[√] Connected device (1 available)
• BV5800 (mobile) • BV5800DK0062697 • android-arm64 • Android 8.1.0 (API 27)
• No issues found!
Could you try with targetSdk 29?
Have in mind that downloads directory is protected. You can’t select it. Try with a different directory and let me know if it worked for you. Thank you!
I set compileSdk and targetSdk versions to 29 with the same result. Tried to choose test subdirectory in the root of Android internal storage. Tested on Android Emulator with API 27 (Android 8.1).
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
�訡�� � �ଠ� ï¿½ï¿½à ¬ï¿½ï¿½ï¿½ -
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Waiting for Android SDK built for x86 to report its views...
Debug service listening on ws://127.0.0.1:50630/C6FsBfc36-E=/ws
Syncing files to device Android SDK built for x86...
D/EGL_emulation( 7141): eglMakeCurrent: 0xe6b2a6c0: ver 3 1 (tinfo 0xcd397670)
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/EGL_emulation( 7141): eglMakeCurrent: 0xdef055a0: ver 3 1 (tinfo 0xcd397900)
D/FilePickerDelegate( 7141): [SingleFilePick] File URI:content://com.android.externalstorage.documents/tree/primary%3Atest/document/primary%3Atest
I/FilePickerUtils( 7141): Caching from URI: content://com.android.externalstorage.documents/tree/primary%3Atest/document/primary%3Atest
D/EGL_emulation( 7141): eglMakeCurrent: 0xe6b2a6c0: ver 3 1 (tinfo 0xcd397670)
D/EGL_emulation( 7141): eglMakeCurrent: 0xdef055a0: ver 3 1 (tinfo 0xcd397900)
E/FilePickerUtils( 7141): Failed to retrieve path: read failed: EISDIR (Is a directory)
D/EGL_emulation( 7141): eglMakeCurrent: 0xe6b2a6c0: ver 3 1 (tinfo 0xcd397670)
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
I/flutter ( 7141): [MethodChannelFilePicker] Could not resolve directory path. Maybe it's a protected one or unsupported (such as Downloads folder). If you are on Android, make sure that you are on SDK 21 or above.
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
D/skia ( 7141): Shader compilation error
D/skia ( 7141): ------------------------
D/skia ( 7141): Errors:
D/skia ( 7141):
Setting compileSdk and targetSdk to 30 didn't help either.
@me21 I have does that happen only with that android device? Could you try with another 8.1 device? This looks odd!
It's a brand new, freshly created Android Virtual Device with the image provided by Google. The physical phone with Android 8.1 gives the same error. I've created another virtual device with Android 8.1 Google Play image (the previous one was Google APIs). Still gives the same error.
I can send you my application code if it helps to reproduce the error, there is nothing confidential inside. Just my application, Flutter SDK and standard Android Virtual Device is needed to reproduce.
Yes that would help. Thank you!
hello_world.zip
Done! My current Flutter version is 1.22 and file_picker plugin version is 2.0.6.
The relevant part of the application is the icon button in the app bar, which should open a directory picker, then return the selected path. It's line 121 in the main.dart file. You can place a breakpoint there.
I have the same issue, in my the tests, I used a real device with android 9.
This PR fixes the problem.
https://github.com/miguelpruivo/flutter_file_picker/pull/433
@allanwolski even if it fixes that issue, that might not be the right solution because sdks below <21 don't support picking directories as per the documentation.
@miguelpruivo but version code Q (a comparison with which was removed in PR) means sdk version 29, not 21, if I'm not mistaken.
@miguelpruivo
The condition for SDK > 21 has not been removed.
if (type.equals("dir") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
uri = DocumentsContract.buildDocumentUriUsingTree(uri, DocumentsContract.getTreeDocumentId(uri));
Log.d(FilePickerDelegate.TAG, "[SingleFilePick] File URI:" + uri.toString());
final String dirPath = FileUtils.getFullPathFromTreeUri(uri, activity);
if(dirPath != null) {
finishWithSuccess(dirPath);
} else {
finishWithError("unknown_path", "Failed to retrieve directory path.");
}
return;
}
@allanwolski I had the conditional access for Android Q for document tree as such:
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && type.equals("dir")) { }
But from what I remember, that was there when scoped storage wasn't supported as workaround.
I'll merge and publish a new version with it.
Thanks!
Published with 2.0.7. Thank you @allanwolski. Let me know if you find any other issue related with it and feel free to reopen this.
Most helpful comment
I have the same issue, in my the tests, I used a real device with android 9.