Fixing `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`

My app suddenly refused to run on my Android Emulator. The error was:

Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
WARNING: [Processor] Library '~/.gradle/caches/modules-2/files-2.1/com.github.canardoux/flutter_sound_core/8.4.2/d794510c32a335c61b742367e24e84ea0b0995c8/flutter_sound_core-8.4.2.aar' contains references to both AndroidX and old support library. This seems like the library is partially migrated. Jetifier will try to rewrite the library anyway.
 Example of androidX reference: 'androidx/arch/core/util/Function'
 Example of support library reference: 'android/support/v4/media/session/MediaSessionCompat$Callback'
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: ~/flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in-5.2.1/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: ~/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_android-2.0.10/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
~/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
~/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
~/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
~/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
~/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
~/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

~/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
~/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 23s
         *********************************************************
WARNING: This version of flutter_tts will break your Android build if it or its dependencies aren't compatible with AndroidX.
         See https://goo.gl/CP92wY for more information on the problem and how to fix it.
         This warning prints for all Android build failures. The real root cause of the error may be unrelated.
         *********************************************************
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

A search on Google leads me to a GitHub ticket with the fix:

App doesn’t compile Android with version 8.2.0 (and 8.2.1) · Issue #685 · Baseflow/flutter-permission-handler
🔙 Regression Old (and correct) behavior The app is compiling with version 8.1.4+2 on Android. Current behavior The app is not compiling because of some BLUETOOTH enum class with version 8.2.0. Here...

Gotta set the compileSdkVersion in app/build.gradle to 31. I changed the value and the app compiled again.