Skip to content

[Camera] Can not use the camera plugin with Android API level 30 #69883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Max-Might opened this issue Nov 5, 2020 · 7 comments · Fixed by flutter/plugins#3299
Closed

[Camera] Can not use the camera plugin with Android API level 30 #69883

Max-Might opened this issue Nov 5, 2020 · 7 comments · Fixed by flutter/plugins#3299
Labels
p: camera The camera plugin package flutter/packages repository. See also p: labels.

Comments

@Max-Might
Copy link

The camera plugin can not be used with Android API level 30 because it uses a deprecated method and warnings are treated as errors.

Steps to Reproduce

  1. Set compile and target API versions in your build.gradle file like to API level 30:
compileSdkVersion = 30
targetSdkVersion = 30

Logs

The build fails with this error:

/home/user/.pub-cache/hosted/pub.dartlang.org/camera-0.5.8+11/android/src/main/java/io/flutter/plugins/camera/Camera.java:333: warning: [deprecation] createCaptureSession(List<Surface>,StateCallback,Handler) in CameraDevice has been deprecated
    cameraDevice.createCaptureSession(surfaceList, callback, null);     
                ^                                                       
error: warnings found and -Werror specified                             
1 error                                                                 
1 warning
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.3, on Linux, locale en_US.UTF-8)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[!] Android Studio
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    ✗ android-studio-dir = ~/Development/android-studio/
    ✗ Android Studio not found at ~/Development/android-studio/
[✓] Connected device (1 available)

! Doctor found issues in 1 category.
@darshankawar
Copy link
Member

@Max-Might
I tried the official camera plugin example on latest stable version (1.22.3), changed compilesdkversion and targetsdkversion to 30 and ran it on Android 11 (API 30) (emulator)and was able to compile and run the app.

Screenshot 2020-11-06 at 1 02 29 PM

Since I don't have a physical device targeting api 30, I am not sure if the issue you are facing is only on physical device. Can you check if on emulator too you get same error ?

@darshankawar darshankawar added in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds labels Nov 6, 2020
@Max-Might
Copy link
Author

Max-Might commented Nov 6, 2020

@darshankawar This is strange.
The error happens because this method signature is marked as deprecated in api level 30:

CameraDevice.createCaptureSession(List<Surface> outputs, 
                CameraCaptureSession.StateCallback callback, 
                Handler handler);

And in the build.gradle file it is configured to treat warnings as errors:

def args = ["-Xlint:deprecation","-Xlint:unchecked","-Werror"]

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Nov 6, 2020
@darshankawar
Copy link
Member

@Max-Might
I am not facing the issue. Updated compilesdkversion and targetsdkversion to 30 and this time used this example which compiled and ran properly without any issues.

Can you try running flutter pub cache repair or flutter clean and then flutter run ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Nov 6, 2020
@kasgaormeo
Copy link

I had encountered the same issue as @Max-Might

flutter pub cache repair -> flutter clean -> flutter run not working.

Instead, I directly declared the Camera.java file in the camera package.

Just did pull request

@DasTobbel
Copy link

Can confirm that issue. Happens to me as soon as the 'compileSdkVersion 30' is used.
Also the issue is not resolved with the suggestion of @darshankawar.
After flutter pub cache repair -> flutter clean -> flutter run
build exits with:

[SomeDirectoryName]/snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/camera-0.5.8+11/android/src/main/java/io/flutter/plugins/camera/Camera.java:333: warning: [deprecation] createCaptureSession(List<Surface>,StateCallback,Handler) in CameraDevice has been deprecated
    cameraDevice.createCaptureSession(surfaceList, callback, null);
                ^
error: warnings found and -Werror specified
1 error
1 warning

running on:
[✓] Flutter (Channel beta, 1.23.0-18.1.pre, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Chrome - develop for the web
[✓] Android Studio
[✓] Connected device (4 available)

@ditman ditman added p: camera The camera plugin p: first party labels Nov 20, 2020
@darshankawar darshankawar added passed first triage and removed in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds labels Nov 23, 2020
@AmbujaAK
Copy link

i too got same issue. any solution ??

@github-actions
Copy link

github-actions bot commented Aug 9, 2021

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2021
@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: camera The camera plugin package flutter/packages repository. See also p: labels.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants