flutter 任务“:camera:compileDebugJavaWithJavac”执行失败

jv4diomz  于 2023-03-31  发布在  Flutter
关注(0)|答案(5)|浏览(216)

我创建了一个新的Flutter项目,并添加了camera插件。添加该依赖后,我得到了许多错误。我使用的Flutter版本是 2.5.2minSdkVersion 21
在 * pubspec.yaml * 文件中

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.4
  camera: ^0.9.4+4

错误如下,

C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\Camera.java:23: error: cannot find symbol
import android.media.EncoderProfiles;
                    ^
  symbol:   class EncoderProfiles
  location: package android.media
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\Camera.java:935: error: cannot find symbol
  EncoderProfiles getRecordingProfile() {
  ^
  symbol:   class EncoderProfiles
  location: class Camera
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:10: error: cannot find symbol
import android.media.EncoderProfiles;
                    ^
  symbol:   class EncoderProfiles
  location: package android.media
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:29: error: cannot find symbol
  private EncoderProfiles recordingProfile;
          ^
  symbol:   class EncoderProfiles
  location: class ResolutionFeature
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:63: error: cannot find symbol
  public EncoderProfiles getRecordingProfile() {
         ^
  symbol:   class EncoderProfiles
  location: class ResolutionFeature
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:187: error: cannot find symbol
  public static EncoderProfiles getBestAvailableCamcorderProfileForResolutionPreset(
                ^
  symbol:   class EncoderProfiles
  location: class ResolutionFeature
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\media\MediaRecorderBuilder.java:8: error: cannot find symbol
import android.media.EncoderProfiles;
                    ^
  symbol:   class EncoderProfiles
  location: package android.media
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\media\MediaRecorderBuilder.java:24: error: cannot find symbol
  private final EncoderProfiles encoderProfiles;
                ^
  symbol:   class EncoderProfiles
  location: class MediaRecorderBuilder
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\media\MediaRecorderBuilder.java:36: error: cannot find symbol
      @NonNull EncoderProfiles encoderProfiles, @NonNull String outputFilePath) {
               ^
  symbol:   class EncoderProfiles
  location: class MediaRecorderBuilder
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\media\MediaRecorderBuilder.java:51: error: cannot find symbol
      @NonNull EncoderProfiles encoderProfiles,
               ^
  symbol:   class EncoderProfiles
  location: class MediaRecorderBuilder
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:186: error: cannot find symbol
  @TargetApi(Build.VERSION_CODES.S)
                                ^
  symbol:   variable S
  location: class VERSION_CODES
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\Camera.java:208: error: reference to MediaRecorderBuilder is ambiguous
      mediaRecorderBuilder = new MediaRecorderBuilder(getRecordingProfileLegacy(), outputFilePath);
                             ^
  both constructor MediaRecorderBuilder(CamcorderProfile,String) in MediaRecorderBuilder and constructor MediaRecorderBuilder(EncoderProfiles,String) in MediaRecorderBuilder match
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:118: error: cannot find symbol
      EncoderProfiles profile =
      ^
  symbol:   class EncoderProfiles
  location: class ResolutionFeature
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:120: error: package EncoderProfiles does not exist
      List<EncoderProfiles.VideoProfile> videoProfiles = profile.getVideoProfiles();
                          ^
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:121: error: package EncoderProfiles does not exist
      EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0);
                     ^
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:200: error: cannot find symbol
          return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_HIGH);
                                 ^
  symbol:   method getAll(String,int)
  location: class CamcorderProfile
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:204: error: cannot find symbol
          return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_2160P);
                                 ^
  symbol:   method getAll(String,int)
  location: class CamcorderProfile
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:208: error: cannot find symbol
          return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_1080P);
                                 ^
  symbol:   method getAll(String,int)
  location: class CamcorderProfile
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:212: error: cannot find symbol
          return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_720P);
                                 ^
  symbol:   method getAll(String,int)
  location: class CamcorderProfile
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:216: error: cannot find symbol
          return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_480P);
                                 ^
  symbol:   method getAll(String,int)
  location: class CamcorderProfile
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:220: error: cannot find symbol
          return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_QVGA);
                                 ^
  symbol:   method getAll(String,int)
  location: class CamcorderProfile
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:224: error: cannot find symbol
          return CamcorderProfile.getAll(cameraIdString, CamcorderProfile.QUALITY_LOW);
                                 ^
  symbol:   method getAll(String,int)
  location: class CamcorderProfile
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:241: error: package EncoderProfiles does not exist
      List<EncoderProfiles.VideoProfile> videoProfiles = recordingProfile.getVideoProfiles();
                          ^
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\features\resolution\ResolutionFeature.java:243: error: package EncoderProfiles does not exist
      EncoderProfiles.VideoProfile defaultVideoProfile = videoProfiles.get(0);
                     ^
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\media\MediaRecorderBuilder.java:32: error: reference to MediaRecorderBuilder is ambiguous
    this(camcorderProfile, outputFilePath, new MediaRecorderFactory());
    ^
  both constructor MediaRecorderBuilder(CamcorderProfile,String,MediaRecorderFactory) in MediaRecorderBuilder and constructor MediaRecorderBuilder(EncoderProfiles,String,MediaRecorderFactory) in MediaRecorderBuilder match
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\media\MediaRecorderBuilder.java:79: error: package EncoderProfiles does not exist
      EncoderProfiles.VideoProfile videoProfile = encoderProfiles.getVideoProfiles().get(0);
                     ^
C:\Users\Lakshan\Documents\SDKs\flutter\.pub-cache\hosted\pub.dartlang.org\camera-0.9.4+4\android\src\main\java\io\flutter\plugins\camera\media\MediaRecorderBuilder.java:80: error: package EncoderProfiles does not exist
      EncoderProfiles.AudioProfile audioProfile = encoderProfiles.getAudioProfiles().get(0);
                     ^
27 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':camera:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 16s
Exception: Gradle task assembleDebug failed with exit code 1

我尝试清除该高速缓存,但同样出现此问题。

afdcj2ne

afdcj2ne1#

尝试将compileSdkVersiontargetSdkVersion更新为31。

iq3niunx

iq3niunx2#

使用此命令:
flutter pub cache repair

jc3wubiy

jc3wubiy3#

我面临着同样的问题后,花了一天得出结论,我们需要升级我们的Flutter版本。

flutter upgrade

或者

flutter upgrade --force
eqfvzcg8

eqfvzcg84#

只要把你的compileSdkVersion改成31就行了。因为我在修改targetSdkVersion的时候又出现了一些错误。

cpjpxq1n

cpjpxq1n5#

尝试将compileSdkVersiontargetSdkVersion更改为31。如果不起作用,请更改 pubspec.yaml 文件并添加以下内容:

camera:
 git:
  url: https://github.com/flutter/plugins
  path: packages/camera/camera
  ref: 9e46048ad2e1f085c1e8f6c77391fa52025e681f

您可以在 [camera] Fix CamcorderProfile Usages #4423 检查修复。

相关问题