【问题标题】:Firebase and Socket.io compatibility issue crash my appFirebase 和 Socket.io 兼容性问题使我的应用程序崩溃
【发布时间】:2020-03-31 20:36:17
【问题描述】:

每次添加 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();
        }
    }

【问题讨论】:

    标签: android firebase sockets


    【解决方案1】:

    我也在使用 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'
    }
    

    【讨论】:

    • com.google.firebase:firebase-firestore 也可能发生这种情况。添加相同的排除命令。
    【解决方案2】:

    我已经测试了你的依赖项,我意识到 firestore 依赖项是崩溃的原因,而不是整个 firebase 依赖项。它似乎不支持您正在使用的 socket.io 类型,甚至根本不支持 socket.io。

    我什至进一步测试了旧版本的 Cloud Firestore,但没有运气 - 应用不断崩溃并出现同样的错误。

    如果您看到错误,请移除 firestore 并同步您的项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-23
      • 1970-01-01
      • 1970-01-01
      • 2018-05-07
      • 2017-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多