Home > Blockchain >  Can't build flutter project when opening it after a long time
Can't build flutter project when opening it after a long time

Time:09-26

Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel'.

FAILURE: Build failed with an exception.

Any help would be appreciated

This didn't fixed it : flutter pub upgrade

Note : I don't want to do this (flutter pub upgrade --major-versions) as doing this breaks the entire project and introduces dozens of more errors and bug

Below is the complete error message:

* Running Gradle task 'assembleRelease'...
/E:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_platform_interface-2.2.0/lib/messages.dart:432:15: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel'.

  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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 { ^^^^^^^^^^^^^^^^^^^^^ /E:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_platform_interface-2.2.0/lib/messages.dart:440:15: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel'.
  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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 { ^^^^^^^^^^^^^^^^^^^^^ /E:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_platform_interface-2.2.0/lib/messages.dart:451:15: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel'.
  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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 { ^^^^^^^^^^^^^^^^^^^^^ /E:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_platform_interface-2.2.0/lib/messages.dart:463:15: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel'.
  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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 { ^^^^^^^^^^^^^^^^^^^^^ /E:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_platform_interface-2.2.0/lib/messages.dart:475:15: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel'.
  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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 { ^^^^^^^^^^^^^^^^^^^^^ /E:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_platform_interface-2.2.0/lib/messages.dart:487:15: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel'.
  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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 { ^^^^^^^^^^^^^^^^^^^^^ /E:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_platform_interface-2.2.0/lib/messages.dart:499:15: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel'.
  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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 { ^^^^^^^^^^^^^^^^^^^^^ /E:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_platform_interface-2.2.0/lib/messages.dart:510:15: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel'.
  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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 { ^^^^^^^^^^^^^^^^^^^^^ /E:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_platform_interface-2.2.0/lib/messages.dart:521:15: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel'.
  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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 { ^^^^^^^^^^^^^^^^^^^^^ /E:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_platform_interface-2.2.0/lib/messages.dart:532:15: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel'.
  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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 { ^^^^^^^^^^^^^^^^^^^^^ /E:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/video_player_platform_interface-2.2.0/lib/messages.dart:544:15: Error: The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel'.
  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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 { ^^^^^^^^^^^^^^^^^^^^^ /E:/src/flutter/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'.
  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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); ^^^^^^^^^^^^^^^^^^^^^ /E:/src/flutter/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'.
  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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 { ^^^^^^^^^^^^^^^^^^^^^ /E:/src/flutter/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'.
  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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); ^^^^^^^^^^^^^^^^^^^^^ /E:/src/flutter/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'.
  • 'BasicMessageChannel' is from 'package:flutter/src/services/platform_channel.dart' ('/E:/src/flutter/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 'E:\src\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1005

  • What went wrong: Execution failed for task ':app:compileFlutterBuildRelease'.

Process 'command 'E:\src\flutter\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 1m 2s Running Gradle task 'assembleRelease'... 63.1s Gradle task assembleRelease failed with exit code 1 Process finished with exit code 1 *

CodePudding user response:

This issue occurs due to older project structure and newer version of plugin conflicts. You can either go with older version of the plugin causing error. Or upgrade your project overall.

you can learn more here: https://flutter.dev/docs/development/packages-and-plugins/plugin-api-migration

CodePudding user response:

If you wanna use old version of then try removing the ^ for every package and then specifying the version number that you used before.

Example:

From

device_info_plus: ^2.1.0

To

device_info_plus: 2.1.0

Why to do so? The caret sign is like range. If you have a higher version of the package then it'll be used if it doesn't have any breaking changes (I suspect that that has failed to see the breaking change here). Learn more about ^ it here

  • Related