miguelpruivo / flutter_file_picker

File picker plugin for Flutter, compatible with mobile (iOS & Android), Web, Desktop (Mac, Linux, Windows) platforms with Flutter Go support.
MIT License
1.29k stars 628 forks source link

Android crashes on image pick [HUAWEI P30 Pro] - Android 10/11 #1534

Open ynnob opened 1 month ago

ynnob commented 1 month ago

Describe the bug Same as the closed issues #1461 , #1460 Fix should have been #1458

But for me and looking at the comments some other the app is still crashing after selecting an image using the file_picker 8.0.5

Permissions i list in my Manifest:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.USE_BIOMETRIC" />
    <!--Geolocator plugin-->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <!-- Images -->
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

    <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
    <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
    <uses-permission
        android:name="android.permission.READ_EXTERNAL_STORAGE"
        android:maxSdkVersion="32" />
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="32" />

    <!--Audio Recording-->
    <uses-permission android:name="android.permission.RECORD_AUDIO" />

and in Application-Tag:
android:requestLegacyExternalStorage="true"

Platform

Platform OS version HUAWEI P30 Pro Android 10

How are you picking?

 result = await FilePicker.platform.pickFiles(
        type: FileType.image,
        allowMultiple: true,
      );

Details to reproduce the issue Provide all the details to reproduce the issue.

Error Log

E/AndroidRuntime(16782): FATAL EXCEPTION: Thread-9
E/AndroidRuntime(16782): Process: com.my.app, PID: 16782
E/AndroidRuntime(16782): java.lang.RuntimeException: java.io.IOException: Permission denied
E/AndroidRuntime(16782):    at com.mr.flutter.plugin.filepicker.FileUtils.compressImage(FileUtils.java:111)
E/AndroidRuntime(16782):    at com.mr.flutter.plugin.filepicker.FilePickerDelegate$2.run(FilePickerDelegate.java:137)
E/AndroidRuntime(16782):    at java.lang.Thread.run(Thread.java:929)
E/AndroidRuntime(16782): Caused by: java.io.IOException: Permission denied
E/AndroidRuntime(16782):    at java.io.UnixFileSystem.createFileExclusively0(Native Method)
E/AndroidRuntime(16782):    at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:317)
E/AndroidRuntime(16782):    at java.io.File.createTempFile(File.java:2018)
E/AndroidRuntime(16782):    at com.mr.flutter.plugin.filepicker.FileUtils.createImageFile(FileUtils.java:120)
E/AndroidRuntime(16782):    at com.mr.flutter.plugin.filepicker.FileUtils.compressImage(FileUtils.java:98)
E/AndroidRuntime(16782):    ... 2 more
I/HwViewRootImpl(16782): removeInvalidNode all the node in jank list is out of time
D/DecorView(16782): showOrHideHighlightView: hasFocus=true; winMode=1; isMrgNull=true
W/InputMethodManager(16782): startInputReason = 1
W/HwRemoteInputMethodManager(16782): isCasting false because IHwDistributedWindowManager is invalid.
D/SessionLifecycleClient(16782): Sending lifecycle 2 to service
D/SessionLifecycleService(16782): Activity backgrounding at 1237470
W/ile.developmen(16782): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/ile.developmen(16782): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/ile.developmen(16782): Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed)
W/ile.developmen(16782): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/ile.developmen(16782): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
I/Process (16782): Sending signal. PID: 16782 SIG: 9
Lost connection to device.

Flutter Version details

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.22.1, on Microsoft Windows [Version 10.0.19045.4529], locale de-DE)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Enterprise 2022 17.8.3)
[√] Android Studio (version 2023.3)
[√] VS Code (version 1.89.1)
[√] Connected device (4 available)
[√] Network resources

• No issues found!
ynnob commented 1 month ago

build.gradle:

android {
    namespace = "com.my.app"
    compileSdk = 34
    ndkVersion "26.1.10909125"

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    // Default Config - Production
    defaultConfig {
        applicationId "com.my.app"
        minSdkVersion 21
        targetSdkVersion 34
        versionCode = flutterVersionCode.toInteger()
        versionName = flutterVersionName
        multiDexEnabled true
    }

[...]
}

Edit: I could confirm the Android Version of this EMUI V12 and it is Android 10 in this case.

github-actions[bot] commented 3 weeks ago

This issue is stale because it has been open for 7 days with no activity.

murat-ti commented 2 weeks ago

Same here, problem in compression, when I set it to 0, the problem dissappears. By default compression value is 30.

ynnob commented 2 weeks ago

Same here, problem in compression, when I set it to 0, the problem dissappears. By default compression value is 30.

Maybe i should set the compression to 0. I didn't even notice that there is a default compression. Thank you! But anyway i think this is still a bug and the previous issues should not have been closed.

rafagazani commented 2 weeks ago

Same problem with xiaomi mi 8 lite MIUI Global 12.0.3 Android 10 QKQ1.190910.002

I disabled compression and it worked

github-actions[bot] commented 1 week ago

This issue is stale because it has been open for 7 days with no activity.

Amoghpurohit commented 4 days ago

Anyone facing this issue just set compressionQuality to 0 and it will work fine (its 30 by default), we can close this issue for now ig

ynnob commented 3 days ago

this issue just set compressio

That is just a workaround not a fix. A native default feature of file_picker should not crash any device.

rohinton-collins commented 3 days ago

Also just hit this. Wasted a lot of time on permissions etc. trying to get things working. As above, set compressionQuality to zero:

    FilePickerResult? result = await FilePicker.platform.pickFiles(type: FileType.image, compressionQuality: 0);

This needs to be fixed.

Amoghpurohit commented 3 days ago

this issue just set compressio

That is just a workaround not a fix. A native default feature of file_picker should not crash any device.

we all know this, getting a workaround and moving on is better than waiting for a fix which who knows when, i think, but your right, lets not close the issue

GopalAngkas commented 1 day ago

I managed to work around with help of permission_hander package

    var compressionQuality = 30;
    var status = await Permission.storage.status;

    if (status.isDenied) {
      status = await Permission.storage.request();
      if (status.isDenied) {
        compressionQuality = 0;
      }
    }

    final result = await FilePicker.platform.pickFiles(
      type: FileType.image,
      compressionQuality: compressionQuality,
    );