【问题标题】:How to resolve "Exception: Gradle task assembleDebug failed with exit code 1"?如何解决“异常:Gradle 任务 assembleDebug 失败,退出代码 1”?
【发布时间】:2021-12-06 05:29:40
【问题描述】:

Flutter 版本:2.6.0-12.0.pre.381

飞镖版本:2.15.0

Gradle 版本:distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip

在 pubspec.yaml 中,我有这些包:

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  splashscreen: ^1.2.0
  bottom_navy_bar:
  cupertino_icons: ^1.0.2
  image_picker: ^0.8.0+4
  fluttertoast: ^8.0.7
  shared_preferences: ^2.0.6
  share: ^2.0.4
  flutter_barcode_scanner: ^2.0.0-nullsafety.0
  dropdown_search: ^1.0.0
  syncfusion_flutter_pdfviewer:
  ndialog: ^4.1.0
  flutter_pdfview: ^1.0.4
  http: ^0.13.3
  dio: ^4.0.0
  path_provider: ^2.0.3
  downloads_path_provider_28: ^0.1.2
  permission_handler: ^8.1.4+2
  open_file: ^3.2.1
  flutter_local_notifications: ^9.0.0

相同的包正在另一个项目中工作。 有关如何解决问题的任何建议。我认为这是由于 build.graddle 中的一些错误。

我已将 build.gradle 中的 minSdkVersion 和 targetSdkVersion 更改如下:

        minSdkVersion 23
        targetSdkVersion 29
        multiDexEnabled true       

运行项目时显示错误:

Launching lib\main.dart on SM M205F in debug mode...
Running Gradle task 'assembleDebug'...
Note: C:\flutter\.pub-cache\hosted\pub.dartlang.org\downloads_path_provider_28-0.1.2\android\src\main\java\it\nplace\downloadspathprovider\DownloadsPathProviderPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: C:\flutter\.pub-cache\hosted\pub.dartlang.org\image_picker-0.8.4+2\android\src\main\java\io\flutter\plugins\imagepicker\ImagePickerDelegate.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:58: error: cannot find symbol
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
                                                            ^
  symbol:   variable R
  location: class VERSION_CODES
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:59: error: cannot find symbol
                status = Environment.isExternalStorageManager()
                                    ^
  symbol:   method isExternalStorageManager()
  location: class Environment
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:254: error: cannot find symbol
                    if (permission == PermissionConstants.PERMISSION_GROUP_MANAGE_EXTERNAL_STORAGE && Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
                                                                                          ^
  symbol:   variable R
  location: class VERSION_CODES
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:268: error: cannot find symbol
            } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && permission == PermissionConstants.PERMISSION_GROUP_MANAGE_EXTERNAL_STORAGE) {
                                                                   ^
  symbol:   variable R
  location: class VERSION_CODES
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:270: error: cannot find symbol
                        Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
                                ^
  symbol:   variable ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
  location: class Settings
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:321: error: cannot find symbol
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
                                                           ^
  symbol:   variable S
  location: class VERSION_CODES
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:349: error: cannot find symbol
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
                                                               ^
  symbol:   variable R
  location: class VERSION_CODES
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:380: error: cannot find symbol
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
                                                                   ^
  symbol:   variable R
  location: class VERSION_CODES
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionManager.java:384: error: cannot find symbol
                    return Environment.isExternalStorageManager()
                                      ^
  symbol:   method isExternalStorageManager()
  location: class Environment
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:64: error: cannot find symbol
            case Manifest.permission.MANAGE_EXTERNAL_STORAGE:
                                    ^
  symbol:   variable MANAGE_EXTERNAL_STORAGE
  location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:72: error: cannot find symbol
            case Manifest.permission.BLUETOOTH_SCAN:
                                    ^
  symbol:   variable BLUETOOTH_SCAN
  location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:74: error: cannot find symbol
            case Manifest.permission.BLUETOOTH_ADVERTISE:
                                    ^
  symbol:   variable BLUETOOTH_ADVERTISE
  location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:76: error: cannot find symbol
            case Manifest.permission.BLUETOOTH_CONNECT:
                                    ^
  symbol:   variable BLUETOOTH_CONNECT
  location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:235: error: cannot find symbol
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && hasPermissionInManifest(context, permissionNames, Manifest.permission.MANAGE_EXTERNAL_STORAGE ))
                                                                ^
  symbol:   variable R
  location: class VERSION_CODES
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:235: error: cannot find symbol
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && hasPermissionInManifest(context, permissionNames, Manifest.permission.MANAGE_EXTERNAL_STORAGE ))
                                                                                          ^
  symbol:   variable MANAGE_EXTERNAL_STORAGE
  location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:236: error: cannot find symbol
                    permissionNames.add(Manifest.permission.MANAGE_EXTERNAL_STORAGE);
                                                           ^
  symbol:   variable MANAGE_EXTERNAL_STORAGE
  location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:259: error: cannot find symbol
                String result = determineBluetoothPermission(context, Manifest.permission.BLUETOOTH_SCAN);
                                                                                         ^
  symbol:   variable BLUETOOTH_SCAN
  location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:270: error: cannot find symbol
                String result = determineBluetoothPermission(context, Manifest.permission.BLUETOOTH_ADVERTISE);
                                                                                         ^
  symbol:   variable BLUETOOTH_ADVERTISE
  location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:281: error: cannot find symbol
                String result = determineBluetoothPermission(context, Manifest.permission.BLUETOOTH_CONNECT);
                                                                                         ^
  symbol:   variable BLUETOOTH_CONNECT
  location: class permission
C:\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.2.5\android\src\main\java\com\baseflow\permissionhandler\PermissionUtils.java:370: error: cannot find symbol
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && hasPermissionInManifest(context, null, permission )) {
                                                        ^
  symbol:   variable S
  location: class VERSION_CODES
20 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':permission_handler: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 44s
Exception: Gradle task assembleDebug failed with exit code 1

【问题讨论】:

    标签: flutter android-studio gradle build.gradle


    【解决方案1】:

    遇到同样的问题,我就是这样解决的:

    首先我从我的 yaml 文件中删除了 permission_handler。

    然后做了一个颤振清洁。

    在 pubspec.yaml 中:我将 permission_handler 插件的版本从 8.2.6 更改为:

    permission_handler: ^8.2.0
    

    然后在android/app/build.grale文件中:将compile sdk版本改为31。

    【讨论】:

    • 将编译 SDK 改为 31 版本就足够了。另一种解决方案是将 permission_handler 恢复为 8.2.0,而不是两者。
    • 即使更改为 31,我的错误仍然存​​在
    【解决方案2】:

    这是由于compileSdkVersion 而发生的。前往 android/app/build.gradle 并将 complieSdkVersion 更改为 31。

    android {
        compileSdkVersion 31
        ...
    }
    

    pubspec.yaml 文件中:-

    dependencies:
      permission_handler: ^8.2.5
    

    该错误必须在 8.2.0 及更高版本中发生。如果仍然遇到错误,请安装低于 8.2.0 的版本。

    【讨论】:

    • 在我的情况下,我没有安装权限处理程序,但它是我安装的软件包之一的依赖项 (form_builder_file_picker)
    【解决方案3】:

    我在 pubspec.yaml 中将 permission_handler: ^8.1.4+2 更改为 permission_handler: 6.0.0 。现在项目运行良好。感谢您的帮助。

    【讨论】:

      【解决方案4】:

      我认为 Build.VERSION_CODES.R 是 API 级别 30,因此将 compileSdkVersion 设置为 30 应该可以解决问题。

      【讨论】:

      • 它没有用。它再次显示相同的错误。
      • 问题是因为permission_handler: ^8.1.4+2 包而发生的。我删除了这个包并运行了它现在正在运行的项目。只有我必须添加另一个包,请建议替代包。
      猜你喜欢
      • 2020-10-18
      • 2021-01-05
      • 2020-10-31
      • 2021-08-02
      • 2021-12-09
      • 2021-06-20
      • 2020-11-06
      • 1970-01-01
      • 2021-06-13
      相关资源
      最近更新 更多