首页 > 解决方案 > Firebase 和 Socket.io 兼容性问题使我的应用程序崩溃

问题描述

每次添加 firebase 依赖项、运行我的应用程序并将套接字连接到端点时,我的应用程序都会立即崩溃。

我同时使用 firebase 和 socket.io,由于兼容性问题导致崩溃。firebase 和 socket.io 可以一起使用吗?

当我添加 firebase 并尝试在我的项目中连接到 socket.io 时出现以下错误

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)

我的依赖:

    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'
    }

端点


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

联系。我正在使用 Application 类来创建套接字模型。

        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();
        }
    }

标签: androidfirebasesockets

解决方案


我也在使用 com.github.nkzawa:socket.io-client:0.6.0。在应用程序消息模块中添加firebase后,我也发生了崩溃,对我来说,快速修复(直到这将被修复,希望很快..)是添加排除..希望它有帮助..

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

我的完整 gradle 文件:(使用 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'
}

推荐阅读