'Execution failed for task ':app:compileFlutterBuildRelease'

I'm currently managing several flutter projects, and some of them are old, and I can't touch the flutter version. To handle multi-flutter version I have implemented the Flutter FVM https://medium.com/dsf-developers/how-to-hold-multiple-versions-of-flutter-b97f69d1a1e0

My new projects run in Flutter 2.10.5, but I have old projects that run on 2.0.4.

Before implementing the Flutter FVM everything worked great in the old projects, but now the following error appears when trying to run the command flutter build appbundle --release:

The plugin `flutter_hls_parser` uses a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs.
If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.

Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/visibility_detector-0.1.5/lib/src/visibility_detector_layer.dart:276:21: Error: Too many positional arguments: 1 allowed, but 2 found.
Try removing the extra positional arguments.
    super.addToScene(builder, layerOffset);
                    ^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/wakelock_platform_interface-0.1.0+1/lib/messages.dart:96:17: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel<dynamic>'.
 - 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/C:/src/flutter/packages/flutter/lib/src/services/platform_channel.dart').
Try correcting the name to the name of an existing method, or defining a method named 'setMockMessageHandler'.
        channel.setMockMessageHandler(null);
                ^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/wakelock_platform_interface-0.1.0+1/lib/messages.dart:98:17: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel<dynamic>'.
 - 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/C:/src/flutter/packages/flutter/lib/src/services/platform_channel.dart').
Try correcting the name to the name of an existing method, or defining a method named 'setMockMessageHandler'.
        channel.setMockMessageHandler((dynamic message) async {
                ^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/wakelock_platform_interface-0.1.0+1/lib/messages.dart:111:17: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel<dynamic>'.
 - 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/C:/src/flutter/packages/flutter/lib/src/services/platform_channel.dart').
Try correcting the name to the name of an existing method, or defining a method named 'setMockMessageHandler'.
        channel.setMockMessageHandler(null);
                ^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/wakelock_platform_interface-0.1.0+1/lib/messages.dart:113:17: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel<dynamic>'.
 - 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/C:/src/flutter/packages/flutter/lib/src/services/platform_channel.dart').
Try correcting the name to the name of an existing method, or defining a method named 'setMockMessageHandler'.
        channel.setMockMessageHandler((dynamic message) async {
                ^^^^^^^^^^^^^^^^^^^^^


FAILURE: Build failed with an exception.

* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1102

* What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* 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 18s

I can run the App in the emulator & real device. I could also upload the iOS version to TestFlight. The flutter doctor returns the following:

[√] Flutter (Channel stable, 2.10.5, on Microsoft Windows [Version 10.0.19043.1586], locale en-GB)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 4.1)
[√] VS Code (version 1.67.0)
[√] Connected device (3 available)
[√] HTTP Host Availability

Although the Flutter doctor says "Flutter channel stable 2.10.5", my VSCode says otherwise (2.0.4):

enter image description here

My fvm_config.json file contains:

{
  "flutterSdkVersion": "2.0.4",
  "flavors": {}
}

I have tried without success:

flutter pub cache repair
flutter clean
flutter pub get


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source