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
161.85k stars 26.57k forks source link

[image_picker] imagePicker.pickVideo(source: ImageSource.camera) returns null after taking a video on Android 33 #145971

Closed wxker95 closed 3 weeks ago

wxker95 commented 1 month ago

Steps to reproduce

On Android 33, after taking a video opened using the camera that was opened by imagePicker.pickVideo(source: ImageSource.gallery), the returned XFile is null

final media = await imagePicker.pickVideo(source: ImageSource.camera);
print(media);

Log: I/flutter ( 4470): null

AndroidManifest.xml

    <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
    <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
    <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

Permissions have also been granted at the point of testing

Expected results

The XFile returned to not be null

Actual results

The XFile returned is null

Code sample

Code sample ```dart import 'package:image_picker/image_picker.dart'; import 'package:permission_handler/permission_handler.dart' as perm; void _incrementCounter() async { await [perm.Permission.camera, perm.Permission.videos, perm.Permission.storage].request(); final media = await ImagePicker().pickVideo(source: ImageSource.camera); print(media); // ... } ```

Screenshots or Video

Screenshots / Video demonstration https://github.com/flutter/flutter/assets/24954885/3a0f34e7-8c06-4682-87c0-43ebe84d9d72

Logs

Logs ```console [Paste your logs here] ```

Flutter Doctor output

Doctor output ```console [√] Flutter (Channel stable, 3.19.3, on Microsoft Windows [Version 10.0.19045.4170], locale en-SG) • Flutter version 3.19.3 on channel stable at D:\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision ba39319843 (3 weeks ago), 2024-03-07 15:22:21 -0600 • Engine revision 2e4ba9c6fb • Dart version 3.3.1 • DevTools version 2.31.1 [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at C:\Users\...\AppData\Local\Android\sdk • Platform android-34, build-tools 34.0.0 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.34) • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools • Visual Studio Build Tools 2019 version 16.11.34601.136 • Windows 10 SDK version 10.0.19041.0 [√] Android Studio (version 2023.2) • Android Studio at C:\Program Files\Android\Android Studio • 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.9+0--11185874) [√] VS Code (version 1.87.2) • VS Code at C:\Users\...\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.84.0 [√] Connected device (4 available) • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 13 (API 33) (emulator) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19045.4170] • Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.86 • Edge (web) • edge • web-javascript • Microsoft Edge 121.0.2277.112 [√] Network resources • All expected network resources are available. ```
huycozy commented 4 weeks ago

Hi @wxker95 Which image_picker_android version are you using? (you can get it from your pubspec.lock file)

I checked this using package's example but didn't see the issue. You can also try and confirm if the issue also occurs. If it persists, could you share a demo video?

wxker95 commented 3 weeks ago

Thanks for the reply @huycozy

I see this in pubspec.lock

image_picker_android:
    dependency: transitive
    description:
      name: image_picker_android
      sha256: "39f2bfe497e495450c81abcd44b62f56c2a36a37a175da7d137b4454977b51b1"
      url: "https://pub.dev"
    source: hosted
    version: "0.8.9+3"

Seems like it's just about the latest version. I'll try to get a demo video up shortly

huycozy commented 3 weeks ago

Please also try upgrading to the latest version image_picker_android: ^0.8.9+5 and retry.

wxker95 commented 3 weeks ago

I have upgraded to the latest version and took a video. Updated the original post. It seems like there is a new stack trace that is logged now that wasn't there before.

E/AndroidRuntime(23643): FATAL EXCEPTION: main
E/AndroidRuntime(23643): Process: com.android.camera2, PID: 23643
E/AndroidRuntime(23643): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.content.ContentValues.put(java.lang.String, java.lang.Long)' on a null object reference
E/AndroidRuntime(23643):        at com.android.camera.VideoModule.saveVideo(VideoModule.java:1263)
E/AndroidRuntime(23643):        at com.android.camera.VideoModule.stopVideoRecording(VideoModule.java:1513)
E/AndroidRuntime(23643):        at com.android.camera.VideoModule.onStopVideoRecording(VideoModule.java:656)
E/AndroidRuntime(23643):        at com.android.camera.VideoModule.onShutterButtonClick(VideoModule.java:697)
E/AndroidRuntime(23643):        at com.android.camera.ShutterButton.performClick(ShutterButton.java:190)
E/AndroidRuntime(23643):        at android.view.View.performClickInternal(View.java:7483)
E/AndroidRuntime(23643):        at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
E/AndroidRuntime(23643):        at android.view.View$PerformClick.run(View.java:29334)
E/AndroidRuntime(23643):        at android.os.Handler.handleCallback(Handler.java:942)
E/AndroidRuntime(23643):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(23643):        at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(23643):        at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(23643):        at android.app.ActivityThread.main(ActivityThread.java:7872)
E/AndroidRuntime(23643):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(23643):        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/AndroidRuntime(23643):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
huycozy commented 3 weeks ago

Thanks for the update. This is similar to https://github.com/flutter/flutter/issues/118443. It seems to appear on emulator only (https://github.com/flutter/flutter/issues/118443#issuecomment-1384287020). More generally, the crash occurs outside the scope of the package, please check https://github.com/flutter/flutter/issues/118443#issuecomment-1454881242.

Closing this as it's not an issue with image_picker package.

github-actions[bot] commented 1 week ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.