flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
162.18k stars 26.64k forks source link

[image_picker: ^1.1.0] Android 12+ image viewer crashes when no images are passed to selected images #147280

Closed Biowulf21 closed 14 hours ago

Biowulf21 commented 3 weeks ago

Steps to reproduce

EDIT: I am using the pickMultiImage function

  1. Click button to open image_picker on android 13
  2. Select a single image
  3. Click View Selected on lower left side of screen
  4. Click Selected button to unselect the single image (add button will reflect 0 images selected)
  5. Click add button

Expected results

Image picker should close when this flow is done, as tested on native android applications.

Actual results

The app crashes.

Code sample

try {
      final picker = ImagePicker();
      final permissionStatus =
          await ImagesUtils.getPhotoPickingPermissionStatus(source);

      if (permissionStatus.isGranted || permissionStatus.isLimited) {
        final image = await picker.pickImage(source: source);
}

} catch (e){
print(e);
}

Screenshots or Video

1000000085

https://github.com/flutter/flutter/assets/77718539/1161df17-f807-45d2-8686-d3d13326a3dd

Logs

Logs ```console E/AndroidRuntime(25551): java.lang.NullPointerException: uri E/AndroidRuntime(25551): at java.util.Objects.requireNonNull(Objects.java:232) E/AndroidRuntime(25551): at android.content.ContentResolver.openInputStream(ContentResolver.java:1511) E/AndroidRuntime(25551): at io.flutter.plugins.imagepicker.FileUtils.getPathFromUri(FileUtils.java:55) E/AndroidRuntime(25551): at io.flutter.plugins.imagepicker.ImagePickerDelegate.handleChooseMultiImageResult(ImagePickerDelegate.java:707) E/AndroidRuntime(25551): at io.flutter.plugins.imagepicker.ImagePickerDelegate.lambda$onActivityResult$1$io-flutter-plugins-imagepicker-ImagePickerDelegate(ImagePickerDelegate.java:609) E/AndroidRuntime(25551): at io.flutter.plugins.imagepicker.ImagePickerDelegate$$ExternalSyntheticLambda1.run(Unknown Source:6) E/AndroidRuntime(25551): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) E/AndroidRuntime(25551): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) E/AndroidRuntime(25551): at java.lang.Thread.run(Thread.java:1012) I/ViewRootImpl@c3d471f[MainActivity](25551): MSG_WINDOW_FOCUS_CHANGED 1 0 D/ViewRootImpl@c3d471f[MainActivity](25551): mThreadedRenderer.initializeIfNeeded()#2 mSurface={isValid=true 0xb4000073ea96d390} D/InputMethodManagerUtils(25551): startInputInner - Id : 0 I/InputMethodManager(25551): startInputInner - IInputMethodManagerGlobalInvoker.startInputOrWindowGainedFocus I/Process (25551): Sending signal. PID: 25551 SIG: 9 Lost connection to device. ```

Flutter Doctor output

Doctor output ```console [✓] Flutter (Channel stable, 3.19.5, on macOS 13.6.1 22G313 darwin-arm64, locale en-PH) • Flutter version 3.19.5 on channel stable at /Users/jamespatrickjilhaney/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 300451adae (4 weeks ago), 2024-03-27 21:54:07 -0500 • Engine revision e76c956498 • Dart version 3.3.3 • DevTools version 2.31.1 [!] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/jamespatrickjilhaney/Library/Android/sdk ✗ cmdline-tools component is missing Run `path/to/sdkmanager --install "cmdline-tools;latest"` See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details. [✓] Xcode - develop for iOS and macOS (Xcode 15.0.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15A507 • CocoaPods version 1.14.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) [✓] VS Code (version 1.88.0) • VS Code at /Users/jamespatrickjilhaney/Downloads/Visual Studio Code.app/Contents • Flutter extension version 3.86.0 [✓] Connected device (4 available) • SM G996N (mobile) • R3CR1068VDD • android-arm64 • Android 14 (API 34) • iPhone SE (3rd generation) (mobile) • BE33B77B-5993-4F32-807B-1CB29C0F7C13 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 13.6.1 22G313 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 119.0.6045.105 [✓] Network resources • All expected network resources are available. ```
danagbemava-nc commented 3 weeks ago

Hi @Biowulf21, is this the only device you're seeing it on or are other devices affected? I tested this on my pixel 7 running android 14 and it doesn't allow me to submit 0 items.

Can you also try uprading to the latest version of image_picker to see if you still experience this issue?

Thank you

Biowulf21 commented 2 weeks ago

Hi @Biowulf21, is this the only device you're seeing it on or are other devices affected? I tested this on my pixel 7 running android 14 and it doesn't allow me to submit 0 items.

Can you also try uprading to the latest version of image_picker to see if you still experience this issue?

Thank you

hi @danagbemava-nc , I tested this on my Samsung S21+ and it crashes the app as well. Huawei P30 Pro also crashes per our QA team.

I'll look into the latest version next week. Thank you!

EDIT: Corrected the device models

danagbemava-nc commented 2 weeks ago

~Please keep us updated~

@Biowulf21, just to confirm, are you calling pickImage or pickMultiImage? On my pixel 7, with pickImage, there isn't the option to select multiple images, but pickMultiImage does allow me to select multiple images.

Biowulf21 commented 2 weeks ago

Hi @danagbemava-nc I'm using pickMultiImage. So sorry for the delay, I'm out of the house right now, but I'll be sure to update this thread later tonight. Thank you!

Edit: I tested the same flow using the latest image_pickers version (1.1.0) and the issue is still there.

danagbemava-nc commented 2 weeks ago

Thanks for the update. Just to confirm, were the samsung s21+ and the huawei p40 both running android 13? Have you tested this on any other OS version?

Biowulf21 commented 1 week ago

Thanks for the update. Just to confirm, were the samsung s21+ and the huawei p40 both running android 13? Have you tested this on any other OS version?

Hello, my team and I tested this on three devices: Huawei P30 Pro (Android 12), Infinix SMART 8 (Android 13), and Samsung 21+ (Android 14).

I also updated the title of the issue for your reference @danagbemava-nc. Sorry for the confusion.

danagbemava-nc commented 1 week ago

Thanks for the update.

While I cannot reproduce this on my device (the picker won't allow sending back 0 items), it seems like we are passing a null URI to https://github.com/flutter/packages/blob/6e6082660b73144e5fedf28545602c1ef6588f8e/packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/FileUtils.java#L55

I think it would be best to catch the null_pointer exception or check if the uri is null before processing.

Labeling for further insight.

Jackson-Antunes-Sampaio commented 1 week ago

I'm facing the same problem in "release".

Using Firebase's "Crashlytics" it returns the error below:

"PlatformException(already_active, Image picker is already active, null, null)"

kvn-DN commented 1 week ago

Facing same problem

"PlatformException(already_active, Image picker is already active, null, null)"

do we have any solutions?

this is delaying the production release.

stuartmorgan commented 5 days ago

This looks like the same issue that https://github.com/flutter/packages/pull/4836 fixed for single-item selection, where some pickers are, instead of returning no clip data, returning clip data with a null URI. It's not fixed for the multi-item codepath yet (see https://github.com/flutter/packages/pull/4836#issuecomment-1730255067 for a suggestion on this).

stuartmorgan commented 1 day ago

Re-opening since the PR didn't fix all codepaths. And in particular, the original report's stack is in handleChooseMultiImageResult, which is the one that's not fixed.

Mairramer commented 1 day ago

@stuartmorgan @gmackall I created a new PR complementing the one I had previously sent.

LouiseHsu commented 1 day ago

i don't remember closing this?

gmackall commented 1 day ago

i don't remember closing this?

I think its just a Github bug, I believe updating the main branch on a fork (maybe only with the github ui?) will sometimes re-close an issue when that update pulls in a commit that contains the description "fixes #issue number".

So if a commit gets merged to main saying "fixed..." but then the issue gets re-opened, and then you update your main branch (and pull in the commit) it will sometimes re-close.

gmackall commented 14 hours ago

This should be fixed by https://github.com/flutter/packages/pull/5009