Nimrodda / flutter_nsd

A Flutter plugin that enables Network Service Discovery (mDNS) on various platforms via their native APIs.
Apache License 2.0
34 stars 8 forks source link

java.lang.IllegalArgumentException: listener not registered #40

Open Liberations opened 2 years ago

Liberations commented 2 years ago

E/AndroidRuntime( 553): FATAL EXCEPTION: NsdManager E/AndroidRuntime( 553): Process: vip.mymei.remote, PID: 553 E/AndroidRuntime( 553): java.lang.IllegalArgumentException: listener not registered E/AndroidRuntime( 553): at com.android.internal.util.Preconditions.checkArgument(Preconditions.java:59) E/AndroidRuntime( 553): at android.net.nsd.NsdManager.getListenerKey(NsdManager.java:496) E/AndroidRuntime( 553): at android.net.nsd.NsdManager.stopServiceDiscovery(NsdManager.java:636) E/AndroidRuntime( 553): at com.nimroddayan.flutternsd.FlutterNsdPlugin$discoveryListener$1.onStartDiscoveryFailed(FlutterNsdPlugin.kt:195) E/AndroidRuntime( 553): at android.net.nsd.NsdManager$ServiceHandler.handleMessage(NsdManager.java:412) E/AndroidRuntime( 553): at android.os.Handler.dispatchMessage(Handler.java:106) E/AndroidRuntime( 553): at android.os.Looper.loopOnce(Looper.java:233) E/AndroidRuntime( 553): at android.os.Looper.loop(Looper.java:334) E/AndroidRuntime( 553): at android.os.HandlerThread.run(HandlerThread.java:67) I/Process ( 553): Sending signal. PID: 553 SIG: 9

Nimrodda commented 2 years ago

Thanks for the report. I need more info. What plugin version? Android version? When did it happen? Is this the full stacktrace? how to reproduce?

vladotesanovic commented 1 year ago

Hi Nimrodd,

Same problem to me:

Plugin version: Private fork based on current master branch ( because current 1.3.3 does not have kotlin_version update ) Android version: 13 Phone: Google Pixel 6

Code to repoduce ( basic example )

@override
  Widget build(BuildContext context, WidgetRef ref) {
    final site = ref.watch(getSiteProvider);
    final flutterNsd = FlutterNsd();
    flutterNsd.stream.listen((nsdServiceInfo) {
      print('Discovered service name: ${nsdServiceInfo.name}');
      print('Discovered service hostname/IP: ${nsdServiceInfo.hostname}');
      print('Discovered service port: ${nsdServiceInfo.port}');
    }, onError: (e) {
      if (e is NsdError) {
        // Check e.errorCode for the specific error
      }
    });

    void startDiscoveryButton() async {
      await flutterNsd.discoverServices('_lisa._tcp.local.');
    }
Where startDiscoveryButton is triggered by:
    TextButton(
            style: ButtonStyle(
              foregroundColor: MaterialStateProperty.all<Color>(Colors.blue),
              overlayColor: MaterialStateProperty.resolveWith<Color?>(
                (Set<MaterialState> states) {
                  if (states.contains(MaterialState.hovered))
                    return Colors.blue.withOpacity(0.04);
                  if (states.contains(MaterialState.focused) ||
                      states.contains(MaterialState.pressed))
                    return Colors.blue.withOpacity(0.12);
                  return null; // Defer to the widget's default.
                },
              ),
            ),
            onPressed: () {
              startDiscoveryButton();
            },
            child: Text('Discover'),
      Full stack trace:
          `E/AndroidRuntime(15051): FATAL EXCEPTION: NsdManager
E/AndroidRuntime(15051): Process: my.package.enduser.home, PID: 15051
E/AndroidRuntime(15051): java.lang.IllegalArgumentException: listener not registered
E/AndroidRuntime(15051):    at android.net.nsd.NsdManager.getListenerKey(NsdManager.java:980)
E/AndroidRuntime(15051):    at android.net.nsd.NsdManager.stopServiceDiscovery(NsdManager.java:1224)
E/AndroidRuntime(15051):    at com.nimroddayan.flutternsd.FlutterNsdPlugin$discoveryListener$1.onStartDiscoveryFailed(FlutterNsdPlugin.kt:195)
E/AndroidRuntime(15051):    at android.net.nsd.NsdManager$ServiceHandler.lambda$handleMessage$1(NsdManager.java:856)
E/AndroidRuntime(15051):    at android.net.nsd.NsdManager$ServiceHandler$$ExternalSyntheticLambda9.run(Unknown Source:6)
E/AndroidRuntime(15051):    at android.net.nsd.NsdManager$$ExternalSyntheticLambda0.execute(Unknown Source:0)
E/AndroidRuntime(15051):    at android.net.nsd.NsdManager$ServiceHandler.handleMessage(NsdManager.java:856)
E/AndroidRuntime(15051):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(15051):    at android.os.Looper.loopOnce(Looper.java:201)
E/AndroidRuntime(15051):    at android.os.Looper.loop(Looper.java:288)
E/AndroidRuntime(15051):    at android.os.HandlerThread.run(HandlerThread.java:67)
I/Process (15051): Sending signal. PID: 15051 SIG: 9`
Nimrodda commented 1 year ago

@vladotesanovic can you try the fix from this commit and tell me if it helps?