Native hybrid development flutter Unhandled Exception: MissingPluginException(No implementation found for method ....

This is a general problem, not just a problem that a certain plug-in method does not support.

Of course, as I said earlier, you can try to clear and reload first to see if the problem can be solved. Sometimes your project does not restart, and hot restart will not recompile the newly added resources.

纯flutter:quit项目->(flutter clean 可不执行)-> flutter run

module混合:module项目flutter pub get -> 原生项目pod install ->再运行启动项目

If the above can solve your problem, then don't read below.

Today I mixed and developed the screen rotation plug-in I wrote before iOS mixing: limiting_direction_csx  Since the company has been using pure flutter for development, there is no problem with using this plug-in. Recently, my friends saw this plug-in, and their company is also trying to use flutter to develop it. The native and flutter mixed method was adopted, which involved the screen rotation support problem. He found this plug-in of mine, but encountered Unhandled Exception: MissingPluginException(No implementation found for method ..... There are no plug-in methods! My friends immediately thought I was a liar, and questioned me in every possible way. So helpless , why did we not consider the problem of module form, haha.

The result was fed back to me, I wrote a mixed demo, tried it myself, and found that all methods are indeed not supported? Can't find it? But there is no problem running the iOS project in the module, and the screen rotates normally.

Later, I got inspiration by referring to this screenshot on github:

The fourth of them is the problem we encountered, that is, our module form is mixed. By default, other plug-ins that interact with the native flutter module will not be re-registered to the native project, so we need a manual way. Register these plugins to connect the bridge in the flutter module with the bridge in the main project. You can follow the registration method in pure flutter's dependent appdelegate.m:

On the iOS side:


#import "ViewController.h"
#import <Flutter/Flutter.h>
#import <FlutterPluginRegistrant/GeneratedPluginRegistrant.h>
#import <limiting_direction_csx/MainViewController.h>
#import "OCViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (IBAction)goFlutterAction:(UIButton *)sender {
    //这里由于屏幕旋转的支持需要将FlutterViewController替换成MainViewController
    MainViewController *flutterViewController = [MainViewController new];
//注册我们的module里面的桥接
    [GeneratedPluginRegistrant registerWithRegistry:flutterViewController];
    [flutterViewController setInitialRoute:@"flutter_login"];
    [self.navigationController pushViewController:flutterViewController animated:YES];
    
    __weak typeof(self) weakSelf = self;
    FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"com.allen.test.call" binaryMessenger:flutterViewController];
    [channel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult  _Nonnull result) {
    // Flutter invokeMethod 特定方法的时候会触发到这里
        if ([call.method isEqualToString:@"getFlutterMessage"]) {
            result(@"接收到flutter的消息,回传信息from OC");
            NSLog(@"接收到flutter的参数:%@",call.arguments);
            [weakSelf goOCVC:call.arguments];
        }
    }];
}

- (void)goOCVC:(NSString *)flutterStr{
    OCViewController *ocVC = [[OCViewController alloc]init];
    ocVC.flutterMsg = flutterStr;
    [self.navigationController pushViewController:ocVC animated:YES];
}


@end

Android (because I am not very proficient in Android for iOS, I will not confuse my children with the code here, and provide a direction, the code should not be very troublesome to write):

。。。。。

 

[GeneratedPluginRegistrant registerWithRegistry:flutterViewController]; Don't register in AppDelegate.m, if you mix it, you need to register before entering each flutter page.

 

Here is my demo link, you can try: https://github.com/KirstenDunst/flutter_integrated_demo.git

 

Guess you like

Origin blog.csdn.net/BUG_delete/article/details/115342517