Flutter:插入新权限包后尝试启动应用程序时出错

Flutter: Error when trying to launch app after inserting new permissions package

我最近将这个权限包添加到我的 flutter 应用程序中:https://pub.dev/packages/permission_handler

我执行的步骤:

  1. 添加了对pubspec.yaml

    的依赖
  2. 将以下内容添加到我的 android 清单中:

    <uses-permission android:name="android.permission.RECORD_AUDIO" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

  3. 我无法为 ios 执行权限操作,因为根据我在网上阅读的内容,Android Studio on Windows 无法模拟ios 设备。我猜我需要购买一台 Apple 笔记本电脑来测试我的应用程序的 iphone 版本。

错误(当 运行 Pixel 2 API 30 上的应用程序时):

Launching lib\main.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...
C:\Users\UserABC\Documents\AndroidStudio\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.3.0\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:\Users\UserABC\Documents\AndroidStudio\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.3.0\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:\Users\UserABC\Documents\AndroidStudio\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.3.0\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:\Users\UserABC\Documents\AndroidStudio\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.3.0\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:\Users\UserABC\Documents\AndroidStudio\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.3.0\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:\Users\UserABC\Documents\AndroidStudio\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.3.0\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:\Users\UserABC\Documents\AndroidStudio\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.3.0\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:\Users\UserABC\Documents\AndroidStudio\flutter\.pub-cache\hosted\pub.dartlang.org\permission_handler-8.3.0\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
8 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 1m 1s
Exception: Gradle task assembleDebug failed with exit code 1

我认为您遗漏了 permission_hendler 包的配置部分。您将按照此 link 解决 figure-out 您的问题。