The method 'setMockMessageHandler' isn't defined for the class 'BasicMessageChannel<dynamic>'

15,961

Solution 1

I had the same problem after update plugin's in AndroidStudio on Mac

flutter pub upgrade

did nothing for me, but

flutter clean
flutter pub upgrade --major-versions

has solved the problem

Solution 2

  1. Go to specified class 'BasicMessageChannel' by press and hold ctrl and click on it
  2. than search for the 'setMockMessageHandler' by ctrl+F than u will see something like this // Looking for setMockMessageHandler? // See this shim package: packages/flutter_test/lib/src/deprecated.dart and paste this line below this comment void setMockMessageHandler(dynamic message){

} but this is just simple hack which is not recommended

Solution 3

I had the same problem today.

from what i could notice, this basically was a breaking change caused by transition of platform channel test interfaces to flutter_test package.

in my case, the problem was resolved just running the flutter pub upgrade on a global terminal session.

see more details about the mentioned transition on referred release notes

Solution 4

Running across this problem after upgrading to Flutter 2.5.3 (from 2.2.3). The change outlined in the release notes broke several hundred tests since the mock method handlers were set in the global setUp() for most tests.

As shown in the release notes, I replaced code like

 MethodChannel('channelName')
   .setMockMethodCallHandler((MethodCall methodCall) {});

with code using the default instance of TestDefaultBinaryMessenger:

 TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
   .setMockMethodCallHandler(MethodChannel('channelName'), (MethodCall methodCall) {});

This change allowed me to keep all tests unchanged.

Solution 5

I have the same problem, I have tried all the above and did not help. flutter pub upgrade and flutter pub upgrade --major-versions outputs this:

No dependencies changed.

1 package is discontinued.

76 packages have newer versions incompatible with dependency constraints.

Try flutter pub outdated for more information.

No changes to pubspec.yaml! The plugins advance_pdf_viewer, flutter_absolute_path, geocoder, google_api_headers, onesignal_flutter use a deprecated version of the Android embedding. To avoid unexpected runtime failures, or future build failures, try to see if these plugins support the Android V2 embedding. Otherwise, consider removing them 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.

Share:
15,961
Aysha Hamna
Author by

Aysha Hamna

Software dev and Freelancer. Curious about the tech world and innovative technologies.

Updated on December 01, 2022

Comments

  • Aysha Hamna
    Aysha Hamna over 1 year

    After running the Flutter project, I get this error. What can I do to solve it?

    Error: The method 'setMockMessageHandler' 
    isn't defined for the class 'BasicMessageChannel<dynamic>'.
    
    FAILURE: Build failed with an exception.
    
  • Abbas Asadi
    Abbas Asadi almost 3 years
    this solution worked for me in Windows. thank you.
  • Zeeshan Ahmad
    Zeeshan Ahmad over 2 years
    so what is the solution?
  • Hosam Eisa
    Hosam Eisa over 2 years
    I have the same problem, only explained what i did, still not working
  • LOLWTFasdasd asdad
    LOLWTFasdasd asdad over 2 years
    I dont want to update all my dependencies. How can I identifiy the specific dependecy which I need to upgrade?
  • Chris
    Chris over 2 years
    Lifesaver! Thanks :D
  • Ajay
    Ajay over 2 years
    This didn't work for me on Mac. Any steps specific to Mac?
  • Mostafijur Rahman
    Mostafijur Rahman about 2 years
    flutter pub upgrade --major-versions It's working fine for me.
  • Rodrigo
    Rodrigo almost 2 years
    best thing to do when legacy need some hotfix