AbdoPrDZ / pusher_client_fixed

Flutter Puscher Client Fixed Version (Fix Kotlin Sdk Error)
MIT License
2 stars 2 forks source link

Error : java.lang.NoSuchMethodError: No direct method <init>(Ljava/util/Map;)V in class Lcom/pusher/client/channel/PusherEvent; #3

Open maulanazh15 opened 10 months ago

maulanazh15 commented 10 months ago

Error : java.lang.NoSuchMethodError: No direct method (Ljava/util/Map;)V in class Lcom/pusher/client/channel/PusherEvent; or its super classes (declaration of 'com.pusher.client.channel.PusherEvent' appears in /data/app/com.example.penjualan_tanah_fe-2/base.apk:classes2.dex)

This error occurred when i am subscribing to private channel, this is the complete error statement in terminal :

E/AndroidRuntime( 6419): FATAL EXCEPTION: pusher-java-client eventQueue E/AndroidRuntime( 6419): Process: com.example.penjualan_tanah_fe, PID: 6419 E/AndroidRuntime( 6419): java.lang.NoSuchMethodError: No direct method (Ljava/util/Map;)V in class Lcom/pusher/client/channel/PusherEvent; or its super classes (declaration of 'com.pusher.client.channel.PusherEvent' appears in /data/app/com.example.penjualan_tanah_fe-2/base.apk:classes2.dex) E/AndroidRuntime( 6419): at com.github.chinloyal.pusher_client.pusher.listeners.FlutterPrivateChannelEventListener.onSubscriptionSucceeded(FlutterPrivateChannelEventListener.kt:22) E/AndroidRuntime( 6419): at com.pusher.client.channel.impl.BaseChannel.lambda$updateState$1$com-pusher-client-channel-impl-BaseChannel(BaseChannel.java:138) E/AndroidRuntime( 6419): at com.pusher.client.channel.impl.BaseChannel$$ExternalSyntheticLambda1.run(D8$$SyntheticClass) E/AndroidRuntime( 6419): at com.pusher.client.util.Factory.lambda$queueOnEventThread$0(Factory.java:140) E/AndroidRuntime( 6419): at com.pusher.client.util.Factory$$ExternalSyntheticLambda0.run(D8$$SyntheticClass) E/AndroidRuntime( 6419): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) E/AndroidRuntime( 6419): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) E/AndroidRuntime( 6419): at java.lang.Thread.run(Thread.java:761)

What is the caused of the error? I am very grateful if this issue is responded, sorry for my bad English grammar. And again thank you very much for the response, if this issue is responded.

AbdoPrDZ commented 10 months ago

hi, please can you include your server and client configurations?.

maulanazh15 commented 10 months ago

My server is using laravel with pusher broadcast driver and laravel-websockets as the websockets, here is my configurations for pusher in laravel .env :

Screenshot 2023-11-01 194142

This is my configurations for pusher client in my flutter app :

Screenshot 2023-11-01 194829

Btw, this error cause my app to stop working like this picture below when i try subscribing to a private channel: Screenshot_1698843732

Although in my laravel websockets dashboard, it successfully subscribe to a private channel :

WebSockets-Dashboard

Yeah that's all the information i can get

Thank you for your respond to this error

AbdoPrDZ commented 10 months ago

As I see everything looks good Have you tried to cleaning your project before? 1- flutter clean 2- Make sure to delete the “build” folder. 3- Delete the application from the emulator. 4- Run the application

maulanazh15 commented 10 months ago

I have tried your method. It's still showing the same error after I do the flutter clean, delete the app in emulator, and rerun the application.

AbdoPrDZ commented 10 months ago

i found your project in your profile i tested it, i faced the same error I searched for the root of the problem but did not find it I tried to separate the command of listening to the event from the command of subscribe to the channel, and the method worked But I did not find what is the root problem Note: some times your method is working

i think the safe way is put the listen command after subscribing in onSubscribeSuccess event

final channel = LaravelEcho.instance.private('channelName');
channel.onSubscribedSuccess(() {
  channel.listen('eventName', (event) {
    print(
      'event[${event.runtimeType}]: $event', // event[String]: {"key": "value"}
    );
    print(
      'decodedData: ${jsonDecode(event)}', // decodedData: {"key": "value"}
    );
  });
});

Note: event is not a class, is a sended data (String)

AbdoPrDZ commented 10 months ago
maulanazh15 commented 10 months ago

Thank you very much for your response, i didn't expect you also try my project to fix this error. I have tried your method, i change the library from laravel_echo to laravel_echo_null 0.0.5+7 from you, and then write the code for subscribing private channel just like your code, but somehow it's still showing the same error. This is my function to create laravel echo :

Echo<PUSHER.PusherClient, PusherChannel> createLaravelEcho(String token) {
  Echo<PUSHER.PusherClient, PusherChannel> echo = Echo.pusher(
    PusherConfig.key,
    authEndPoint: PusherConfig.hostAuthEndPoint, // String?: auth host
    authHeaders: {
      // authenticate headers
      'Authorization': 'Bearer $token',
      'Content-Type': 'application/json',
      'Accept': 'application/json',
    },
    // cluster: PusherConfig.cluster, // String?: pusher cluster
    host: '10.0.2.2',
    wsPort: 6001,
    encrypted: false,
    activityTimeout: 120000,
    pongTimeout: 30000,
    maxReconnectionAttempts: 6,
    maxReconnectGapInSeconds: 30,
    enableLogging: true,
    autoConnect: true, // bool: client connection automatically
    nameSpace: 'nameSpace',
  );

  return echo;
}

I change the autoConnect option to true, because the laravel_echo_null seems not auto connect itself. This is my code for subscribing to private channel :

void listenChatChannel(ChatEntity chat) {
    // print(LaravelEcho.socketId);

    final channel = LaravelEcho.instance.private('chat.${chat.id}');
    channel.onSubscribedSuccess(() {
      channel.listen('.message.sent', (event) {
        print(
          'event[${event.runtimeType}]: $event', // event[String]: {"key": "value"}
        );
        print(
          'decodedData: ${jsonDecode(event)}', // decodedData: {"key": "value"}
        );
      });
    });
  }

When i run the application, its still showing the same error. Although the onSubscribedSuccess is successfully running, the prove is on the debug console log :

image

The error shows after the onSubscribedSucces successfully running :

image

I also try to comment the channel.onSubscribedSuccess, just to confirm when the problem occured, is it after, before, or as the subcribing process run.

void listenChatChannel(ChatEntity chat) {
    // print(LaravelEcho.socketId);

    final channel = LaravelEcho.instance.private('chat.${chat.id}');
    // channel.onSubscribedSuccess(() {
    //   channel.listen('.message.sent', (event) {
    //     print(
    //       'event[${event.runtimeType}]: $event', // event[String]: {"key": "value"}
    //     );
    //     print(
    //       'decodedData: ${jsonDecode(event)}', // decodedData: {"key": "value"}
    //     );
    //   });
    // });
  }

And its still show the same error. My guess, the problem occurred after subscribing process is done, because in my laravel-websockets, its successfully subscribe to private channel just like this :

image

Does the Android version in the emulator also affect the errors? What Android version you are using for the emulator? My Android version for the emulator is Android 7.0.

Yeah, I also try the socket_io_client, laravel_echo_null, and fixed-laravel-echo-server, but the problem is, when subscribing to a private channel, the request for authorizing to private channel from socket_io_client, the socket_id is null. It seems, that the socket_io_client didn't include the socket_id in their request. Or is the problem in laravel-echo-null? This is my error log in fixed-laravel-echo-server :

image

I am using http subscriber in fixed-laravel-echo-server, and pusher as the broadcast driver in laravel. I have not try the redis subscriber in fixed-laravel-echo-server and redis as broadcast driver in laravel though, i don't know how it works. Maybe I will try that, if i am not finding the solution for the socket_id request in the http subscriber.

Thank you very much for your response to this issue. Sorry for the delayed comment from me.

Djihanegh commented 9 months ago

I got the same error

adekmaulana commented 1 month ago

i got the same error

amdkholil commented 1 month ago

same error..

I/flutter (17983): previousState: CONNECTING, currentState: CONNECTED
E/AndroidRuntime(17983): FATAL EXCEPTION: pusher-java-client eventQueue
E/AndroidRuntime(17983): Process: com.example.app, PID: 17983
E/AndroidRuntime(17983): java.lang.NoSuchMethodError: No direct method <init>(Ljava/util/Map;)V in class Lcom/pusher/client/channel/PusherEvent; or its super classes (declaration of 'com.pusher.client.channel.PusherEvent' appears in /data/app/~~ET9cc-_bILXAszc5-V9jrQ==/com.example.app-jHS1aMRPd1T4wcKUI8-lHQ==/base.apk)
E/AndroidRuntime(17983):    at com.github.chinloyal.pusher_client.pusher.listeners.FlutterBaseChannelEventListener.onSubscriptionSucceeded(FlutterBaseChannelEventListener.kt:41)
E/AndroidRuntime(17983):    at com.pusher.client.channel.impl.BaseChannel.lambda$updateState$1$com-pusher-client-channel-impl-BaseChannel(BaseChannel.java:138)
E/AndroidRuntime(17983):    at com.pusher.client.channel.impl.BaseChannel$$ExternalSyntheticLambda1.run(Unknown Source:2)
E/AndroidRuntime(17983):    at com.pusher.client.util.Factory.lambda$queueOnEventThread$0(Factory.java:140)
E/AndroidRuntime(17983):    at com.pusher.client.util.Factory$$ExternalSyntheticLambda0.run(Unknown Source:2)
E/AndroidRuntime(17983):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
E/AndroidRuntime(17983):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
E/AndroidRuntime(17983):    at java.lang.Thread.run(Thread.java:1012)
I/Process (17983): Sending signal. PID: 17983 SIG: 9
Lost connection to device.

Exited.
AbdoPrDZ commented 4 weeks ago

@everyone

Hey, there i create this package that works on all platforms

pusher_client_socket

Please i need everyone to try it and let me know if you face any problem with it so I can improve it.