CarnegieTechnologies / gallery_saver

Flutter plugin that saves images and videos to devices gallery
Apache License 2.0
157 stars 313 forks source link

Android release app crashes after image download #184

Open nattesh opened 2 years ago

nattesh commented 2 years ago

Hi, I'm here to report a very particular issue. The library is awesome and it works as expected in iOS in any circumstance. Using Android everything is good running the debug version of the apk, but when I build the release version of the apk and try to download an image the app just crashes. Thing is: app crashes just after the download.

I'm using v2.3.2.

Here's the code snippet:

void _saveNetworkImage() async {
    _startDownloading();
    String path = widget.details.path;
    await GallerySaver.saveImage(path);
    _endDownloading();
  }

  void _startDownloading() {
    setState(() {
      downloading = true;
    });
  }

  void _endDownloading() {
    setState(() {
      downloading = false;
      done = true;
    });
  }

You may notice that there's nothing more than the download and two state updates that involve only two flags (just to handle a circular spinner showed during the download).

The logcat: 2022-04-26 18:40:43.369 3921-3921/? V/LogicalMediaSource: onSourceMediaCreated() - media: [MediaStore/121, /storage/emulated/0/Pictures/<filename>], flags: 0 2022-04-26 18:40:43.570 10571-10652/? E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1 Process: <build> PID: 10571 java.lang.IllegalAccessError: Illegal class access: 'e.a.c' attempting to access 'kotlinx.coroutines.J' (declaration of 'e.a.c' appears in base.apk) at e.a.c.invokeSuspend(Unknown Source:50) at h.m.o.a.a.resumeWith(:2) at kotlinx.coroutines.L.run(Unknown Source:86) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6863) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 2022-04-26 18:40:43.571 483-483/? E/SELinux: avc: denied { find } for service=opdiagnose pid=10571 uid=10119 scontext=u:r:untrusted_app:s0:c119,c256,c512,c768 tcontext=u:object_r:opdiagnose_service:s0 tclass=service_manager permissive=0 2022-04-26 18:40:43.572 483-483/? E/SELinux: avc: denied { find } for service=opdiagnose pid=10571 uid=10119 scontext=u:r:untrusted_app:s0:c119,c256,c512,c768 tcontext=u:object_r:opdiagnose_service:s0 tclass=service_manager permissive=0 2022-04-26 18:40:43.572 10571-10652/? W/OPDiagnose: getService:OPDiagnoseService NULL

Tested on two different devices (OnePlus 7 and OnePlus 3), with stock rom and fully updated (if you're wondering about SELinux). Mind that the picture is actually saved, so if I check the picture in the gallery app I can see it and use it.

Here's my flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.4, on macOS 12.3.1 21E258 darwin-x64, locale
    it-IT)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] Android Studio (version 3.6)
[✓] Android Studio (version 3.6)
[✓] IntelliJ IDEA Community Edition (version 2021.3.3)
[✓] VS Code (version 1.66.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

• No issues found!

Thank you in advance for any help.

saixin commented 2 years ago

any update? i face it too.

AyeshaIftikhar commented 2 years ago

Any update over this issue ?

saixin commented 2 years ago

maybe you have not set permission to save photo to gallery. add this to ios/runner/info.plist <key>NSPhotoLibraryUsageDescription</key> <string>Photo Gallery Set Avatar</string>

you may need permission_handler plugin to check if have perssion to save photo.

Permission.storage.request().then((value)async { if(PermissionStatus.granted == value) { //your code } });

nattesh commented 2 years ago

Thank you for your kind reply. As I said, permissions are set in fact the image is correctly saved on the device (and I can see it browsing the gallery once the app is crashed).

AyeshaIftikhar commented 2 years ago

maybe you have not set permission to save photo to gallery. add this to ios/runner/info.plist <key>NSPhotoLibraryUsageDescription</key> <string>Photo Gallery Set Avatar</string>

you may need permission_handler plugin to check if have perssion to save photo.

Permission.storage.request().then((value)async { if(PermissionStatus.granted == value) { //your code } });

The same case happened to me also. Images are saving successfully but app kept crashing, I then figured out that it was because I was downloading media in bulk at the same time so I added delay in downloading the files and it stopped crashing my application.

Chetan-3110 commented 2 years ago

For me, It shouldn't be the delay crashing the app. I am downloading on tap of a button and mostly one file at a time.