Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase and Socket.io compatibility issue crash my app

Every time add firebase dependencies, run my app and socket connect to endpoint, my app crashes immediately.

I'm using firebase and socket.io together and is causing the crash due to compatibility issues. Can firebase and socket.io be used together?

I get the following error when i added firebase and try to connect to socket.io in my project

E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
    Process: com.project.hubrydemanagerapp, PID: 30101
    java.lang.NoSuchMethodError: No virtual method callEngineGetConnection(Lcom/squareup/okhttp/Call;)Lcom/squareup/okhttp/Connection; in class Lcom/squareup/okhttp/internal/Internal; or its super classes (declaration of 'com.squareup.okhttp.internal.Internal' appears in /data/app/com.project.hubrydemanagerapp-t3ZbPD-QZAE9y2BMT64Cdg==/base.apk!classes3.dex)
        at com.squareup.okhttp.ws.WebSocketCall.createWebSocket(WebSocketCall.java:154)
        at com.squareup.okhttp.ws.WebSocketCall.access$000(WebSocketCall.java:42)
        at com.squareup.okhttp.ws.WebSocketCall$1.onResponse(WebSocketCall.java:102)
        at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:177)
        at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)

My dependencies:

    implementation 'com.google.firebase:firebase-database:19.2.0'
    implementation 'com.google.firebase:firebase-firestore:21.3.0'
    implementation 'com.squareup.okhttp3:okhttp:4.2.2'
    implementation('com.github.nkzawa:socket.io-client:0.6.0') {
        exclude group: 'org.json', module: 'json'
    }

Endpoint


    "https://hubryde-trip-service.herokuapp.com/";
    "https://hubryde-request-service.herokuapp.com/";

Connection. I'm using Application class to create socket model.

        tripSocket = IO.socket(TRIP_URL);
        socket2 = IO.socket(BUS_URL);

        SocketEndpoint app = (SocketEndpoint) getApplication();
        tripSocket = app.getmTripSocket();
        if(!tripSocket.connected()) {
            tripSocket.connect();
        }
        socket2 = app.getmBusLocationSocket();
        if(!socket2.connected()) {
            socket2.connect();
        }
    }
like image 805
KSDev Avatar asked Mar 04 '23 04:03

KSDev


1 Answers

Im also Using com.github.nkzawa:socket.io-client:0.6.0. That crash also happened to me after adding firebase in app messaging module, for me the quick fix (until this will be fixed, hopefully soon..) was to add exclude.. hope it helps..

implementation ('com.google.firebase:firebase-inappmessaging-display:19.0.3') {
    exclude group: 'com.squareup.okhttp', module: 'okhttp'
}

my full gradle file: (Using AndroidX)

implementation 'com.github.nkzawa:socket.io-client:0.6.0'
implementation 'tech.gusavila92:java-android-websocket-client:1.2.2'
implementation  "com.google.firebase:firebase-messaging:20.1.4"
implementation 'com.google.firebase:firebase-core:17.3.0'
implementation 'com.google.firebase:firebase-analytics:17.3.0'
implementation  'com.google.firebase:firebase-auth:19.3.0'
implementation ('com.google.firebase:firebase-inappmessaging-display:19.0.3') {
    exclude group: 'com.squareup.okhttp', module: 'okhttp'
}
like image 181
Benlish Avatar answered Mar 12 '23 20:03

Benlish