简体   繁体   English

基于 Flutter 的 Android 应用程序抛出 MissingPluginException(未找到通道上的方法的实现)

[英]Flutter based Android app throwing MissingPluginException(No implementation found for method on channel)

I am trying to make the native side of my android app to communicate with Flutter.我正在尝试使我的 android 应用程序的本机端与 Flutter 进行通信。

This is on the Flutter side:这是在 Flutter 端:

static const platform = const MethodChannel('getHallInfo');

@override
void initState() {
testing().then((String lst) {
  setState(() {
    if (lst != null) str = lst;
  });
});

super.initState();
}

@override
Widget build(BuildContext context) {
return Column(
  children: <Widget>[Text(str)],
);
}

static Future<String> testing() async {
String lst;
try {
  lst = await platform.invokeMethod('getHalls');
} catch (e) {
  print(e.toString());
}

return lst;
}

And this is on the native Java:这是在本机 Java 上:

private static final String CHANNEL = "getHallInfo";
super.configureFlutterEngine(getFlutterEngine());
GeneratedPluginRegistrant.registerWith(getFlutterEngine());

new MethodChannel(getFlutterEngine().getDartExecutor().getBinaryMessenger(), CHANNEL).setMethodCallHandler(new MethodChannel.MethodCallHandler() {
        @Override
        public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {

            if (methodCall.method.equals("getHalls")) {
              String mm= "Succeeded";
              System.out.println("Entered");
                result.success(mm);
            }

        }
    });

My Pubspec.yaml:我的 Pubspec.yaml:

name: flutterModule

description: A new flutter module project.

version: 1.0.0+1

environment:
 sdk: ">=2.1.0 <3.0.0"

dependencies:
 flutter:
  sdk: flutter

cupertino_icons: ^0.1.3

flutter_svg: ^0.17.4

google_fonts: ^1.1.0

intl: ^0.16.1

dev_dependencies:
 flutter_test:
  sdk: flutter

flutter:
 uses-material-design: true
assets:
- assets/icons/

module:
 androidX: true
 androidPackage: com.example.flutterModule
 iosBundleIdentifier: com.example.flutterModule

This is the error I get:这是我得到的错误:

MissingPluginException(No implementation found for method getHalls on channel getHallInfo) MissingPluginException(在通道 getHallInfo 上找不到方法 getHalls 的实现)

Note: "Entered" is shown on the terminal注意: “输入”显示在终端上

Edit: These are the things that I tried:编辑:这些是我尝试过的事情:

  1. Run flutter clean运行 flutter 清洁
  2. Run flutter upgrade运行flutter升级
  3. Restart the app重启应用

But this exception persists.但是这个例外仍然存在。

you just have to stop the app and restart it again.您只需要停止应用程序并重新启动它。

make sure you did pub get before you stop your app.在停止应用程序之前,请确保您确实pub get use the command.使用命令。

flutter pub get

Try flutter clean尝试flutter clean

then flutter upgrade然后flutter upgrade

then flutter run -v然后flutter run -v

If that doesn't work, have a look at the following issues: issue01 , issue02如果这不起作用,请查看以下问题: issue01issue02

I hope this will help you我希望这能帮到您

you just need to run你只需要运行

Flutter clean

then again restart/run your app然后再次重新启动/运行您的应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (在通道插件上找不到方法 init 的实现。flutter.io/google_sign_in - (No implementation found for method init on channel plugins.flutter.io/google_sign_in 无法解决 flutter 本机通信错误 - 未处理的异常未找到通道上的方法的实现 - Can't resolve flutter native communication error - Unhandled Exception No implementation found for method on Channel 在非Android应用中使用newTrustedTransport方法找不到KeyStoreException JKS实现 - KeyStoreException JKS implementation not found using newTrustedTransport method in a not Android app 在android studio中找不到本机方法的实现 - No implementation found for native method in android studio 找不到方法错误的实现方法 - No implementation method found for method error Android电报应用程序-&gt; java.lang.UnsatisfiedLinkError:找不到无效的实现 - Android Telegram App --> java.lang.UnsatisfiedLinkError: No implementation found for void 如何使用方法通道将自定义 POJO 或 DTO object 从 flutter 传递到 Android? - How to pass a Custom POJO or DTO object from flutter to Android using method channel? 如何在Flutter应用与其android / ios代码之间设置发布-订阅频道? - How to set up a publish-subscribe channel between a Flutter app and it's android/ios code? Android应用程式Pusher的实作 - Implementation of pusher for android app Android JNI NDK - 未找到实现 - Android JNI NDK - No implementation found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM