csdcorp / speech_to_text

A Flutter plugin that exposes device specific text to speech recognition capability.
BSD 3-Clause "New" or "Revised" License
351 stars 218 forks source link

(iOS) 'setMockMethodCallHandler' isn't defined for the class 'MethodChannel' #229

Closed nyiyui closed 2 years ago

nyiyui commented 2 years ago

Flutter Version: 2.2.2 speech_to_text Version: v4.2.1

When building for iOS, the build fails with the following error:

flutter run
Launching lib/main.dart on iPhone 12 Pro Max in debug mode...
Running Xcode build...                                                  
Xcode build done.                                           19.7s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **Xcode's output:
↳
    ../../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/speech_to_text_platform_interface-2.0.0/lib/method_channel_speech_to_text.dart:159:14: Error: The method
    'setMockMethodCallHandler' isn't defined for the class 'MethodChannel'.
     - 'MethodChannel' is from 'package:flutter/src/services/platform_channel.dart' ('../../../../development/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 'setMockMethodCallHandler'.
        _channel.setMockMethodCallHandler(handler);
                 ^^^^^^^^^^^^^^^^^^^^^^^^    Command PhaseScriptExecution failed with a nonzero exit code
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Analyzing workspace
    note: Constructing build description
    note: Build preparation complete
    .../ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0,
    but the range of supported deployment target versions is 9.0 to 14.5.99. (in target 'Try' from project 'Pods')
    .../ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0,
    but the range of supported deployment target versions is 9.0 to 14.5.99. (in target 'Flutter' from project 'Pods')Could not build the application for the simulator.
Error launching application on iPhone 12 Pro Max.
sowens-csd commented 2 years ago

Thanks for the report, that might be a deprecation in 2.2.2, I'll have a look.

sowens-csd commented 2 years ago

Very odd, I just did a build for 2.2.2 on iOS and it worked. However, I can see from here https://flutter.dev/docs/release/breaking-changes/mock-platform-channels that this method is gone, so I kind of understand why it's failing for you, but not why it's working for me. There does appear to be a migration strategy though so I'll work through and see if I can get a build that works for both of us.

sowens-csd commented 2 years ago

Interesting, been trying to follow the migration guide and it doesn't work. Looks like this change doesn't happen until 2.3.0-17.0.pre.1 so some of the tools I'd need to migrate with aren't in 2.2.2. You're currently using the stable channel with 2.2.2?

nyiyui commented 2 years ago

Yes, I'm using Flutter version 2.2.2 on stable.

sowens-csd commented 2 years ago

I've committed a change to the repo that moves the setMock into the test case. Can someone who can reproduce this try it out and let me know if it resolves the issue?

atrope commented 2 years ago

@sowens-csd worked here

joeccleung commented 2 years ago

Have the same issue when building Android APK on Flutter Beta 2.3.0-24.1.pre.

PR #232 fixed the issue. Successful build and the plugin is functioning. Thank you very much!

sheldongoldberg commented 2 years ago

I'm getting that error with Flutter 2.4.0-1.0.pre.115 • channel master •

atrope commented 2 years ago

You guys should add this to your pubspec until @sowens-csd release a new version:

dependency_overrides:
  speech_to_text_platform_interface:
    git:
      url: https://github.com/csdcorp/speech_to_text
      path: speech_to_text_platform_interface
sheldongoldberg commented 2 years ago

Thank you very much. That worked!

Yannick-DonOne commented 2 years ago

Facing the same issue with audio_service: ^0.17.1 package. None of the above solutions have worked.

error is

`/B:/flutter/.pub-cache/hosted/pub.dartlang.org/audio_service-0.17.1/lib/audio_service.dart:675:16: Error: The method 'setMockMethodCallHandler' isn't defined for the class 'MethodChannel'.

/B:/flutter/.pub-cache/hosted/pub.dartlang.org/audio_service-0.17.1/lib/audio_service.dart:1267:12: Error: The method 'setMockMethodCallHandler' isn't defined for the class 'MethodChannel'.

simdev0 commented 2 years ago

I'm also facing the same issue as @Yannick-DonOne

HeshamErfanMDLabs commented 2 years ago

I'm also facing the same issue as @Yannick-DonOne

HeshamErfanMDLabs commented 2 years ago

It looks like this issue is solved at the new prerelease version 0.18.0-beta.0