Unhandled Exception: MissingPluginException(No implementation found for method xxx on channel xxx
Flutter 与 Native 进行通信可能遇到Unhandled Exception: MissingPluginException(No implementation found for method xxx ,通信渠道的方法找不到有可能如下问题1.new MethodChannel(flutterEngine.getDartExecutor(), channelName)生成 Method
Flutter 与 Native 进行通信可能遇到 Unhandled Exception: MissingPluginException(No
implementation found for method xxx ,上面主要是Flutter与Native通信失败,通信渠道的方法找不到有可能如下问题
1.
new MethodChannel(flutterEngine.getDartExecutor(), channelName)
生成 MethodChannel 时Flutter层和Native 层 channelName 字符串不一致
2. Flutter设置 MethodChannel 时引擎和打开页面的引擎不一致
如果是Flutter UI 直接在 FlutterActivity打开,可以重写 configureFlutterEngine
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
MethodChannelManger.getInstance().registerAllMethod(flutterEngine)
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
MethodChannelManger 是自己的Channel注册,GeneratedPluginRegistrant是依赖的第三方需要注册的channel,
如果是View 加载Flutter,需要把View绑定的 引擎ID 和 MethodChannel 进行一致绑定。
如我使用FlutterFragment 加载Flutter页面,而 FlutterFragment 创建的时候是
fragment = FlutterFragment.withCachedEngine("olistEngine").build();
或 fragment = FlutterFragment.withNewEngine().build();此时就绑定了Engine
那么注册的时候通过fragment 即可获取到对应的engine,则绑定注册通信如下
MethodChannel channel = new MethodChannel(fragment.getFlutterEngine().getDartExecutor(), BASEINFO_CHANNEL); FlutterView 和Fragment一样.
更多推荐
所有评论(0)