livekit / client-sdk-android

LiveKit SDK for Android
https://docs.livekit.io
Apache License 2.0
195 stars 77 forks source link

GRPC Data Unmarshalling Error #396

Open aliumujib opened 8 months ago

aliumujib commented 8 months ago

Describe the bug

We're using Livekit in our Android app, calling works well and we're able to create and join rooms. However trying to use the room.localParticipant.publishData mechanism doesn't work. When trying to send the data from the client, it throws the following error which crashes our app:

Screenshot 2024-03-25 at 10 54 04

We also tried moving the publishData call to our backend server, but the app still crashes when the SDK tries to deserialize data received, so RoomEvent.DataReceived is never triggered.

To Reproduce Steps to reproduce the behavior:

  1. Connect to a call with mutliple devices

  2. Try to send some data through the room.localParticipant.publishData function. In our case, we're trying to publish a small JSON payload that has been serialized to bytes.

    {
    "type": "com.reachout.android.calls.ui.base.CallEventSignal.RequestToSpeak",
    "requesterId": "NTuScSP1S9K8hRS45EhqgQ=="
    }
  3. The app crashes with the exception in the screenshot above.

Expected behavior The data should be broadcast to all the participants in the room and be available for deserialization via the RoomEvent.DataReceived event.

Device Info:

Additional context We use GRPC for all network calls in all the app, the we use the following library versions:

versions.grpc = "1.62.2"

def grpc = [:]
grpc.grpc_okhttp = "$groups.grpc:grpc-okhttp:$versions.grpc"
grpc.grpc_stub = "$groups.grpc:grpc-stub:$versions.grpc"
grpc.grpc_protobuff_lite = "$groups.grpc:grpc-protobuf-lite:1.62.2"
grpc.grpc_kotlin_stub = "$groups.grpc:grpc-kotlin-stub:1.4.1"
grpc.grpc_protobuff_kt_lite = "com.google.protobuf:protobuf-kotlin-lite:4.26.0"
deps.grpc = grpc

Protobuff setup:

protobuf {
    protoc {
        if (project.hasProperty('protoc_platform')) {
            artifact = "com.google.protobuf:protoc:21.0-rc-1:${protoc_platform}"
        } else {
            artifact = "com.google.protobuf:protoc:21.0-rc-1"
        }
    }
    plugins {
        grpc {
            artifact = 'io.grpc:protoc-gen-grpc-java:1.62.2' // CURRENT_GRPC_VERSION
        }
        grpckt {
            artifact = "io.grpc:protoc-gen-grpc-kotlin:1.4.1:jdk8@jar"
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                kotlin { option 'lite' }
                java { option 'lite' }
            }
            task.plugins {
                grpc { // Options added to --grpc_out
                    option 'lite'
                }
                grpckt { // Options added to --grpc_out
                    option 'lite'
                }
            }
        }
    }
}
davidliu commented 8 months ago

The error in the screenshot looks like that's when you receive a message from the server. Do you also have one from when you send? Also text error logs would be appreciated instead of screenshots.

aliumujib commented 8 months ago

Thanks for your response @davidliu It is exactly the same error both ways. Please see the logs below:

java.lang.StringIndexOutOfBoundsException: length=23; index=23
    at java.lang.String.charAt(Native Method)
    at com.google.protobuf.MessageSchema.newSchemaForRawMessageInfo(MessageSchema.java:427)
    at com.google.protobuf.MessageSchema.newSchema(MessageSchema.java:221)
    at com.google.protobuf.ManifestSchemaFactory.newSchema(ManifestSchemaFactory.java:85)
    at com.google.protobuf.ManifestSchemaFactory.createSchema(ManifestSchemaFactory.java:71)
    at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:93)
    at com.google.protobuf.MessageSchema.getMessageFieldSchema(MessageSchema.java:4849)
    at com.google.protobuf.MessageSchema.mergeFromHelper(MessageSchema.java:4241)
    at com.google.protobuf.MessageSchema.mergeFrom(MessageSchema.java:3846)
    at com.google.protobuf.GeneratedMessageLite.parsePartialFrom(GeneratedMessageLite.java:1531)
    at com.google.protobuf.GeneratedMessageLite.parsePartialFrom(GeneratedMessageLite.java:1630)
    at com.google.protobuf.GeneratedMessageLite.parseFrom(GeneratedMessageLite.java:1619)
    at com.google.protobuf.GeneratedMessageLite.parseFrom(GeneratedMessageLite.java:1612)
    at livekit.LivekitModels$DataPacket.parseFrom(LivekitModels.java:9997)
    at io.livekit.android.room.RTCEngine.onMessage(RTCEngine.kt:941)
    at io.livekit.android.room.RTCEngine$DataChannelObserver.onMessage(RTCEngine.kt:969)
#
# Fatal error in: gen/jni_headers/sdk/android/generated_metrics_jni/../../../../../../../../../../../_source/android_prefixed/webrtc/src/sdk/android/src/jni/jni_generator_helper.h, line 95
# last system error: 0
# Check failed: !env->ExceptionCheck()
# 
Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 10647 (signaling_threa), pid 10366 (eachout.android)
Cmdline: chat.reachout.android
pid: 10366, tid: 10647, name: signaling_threa  >>> chat.reachout.android <<<
    #01 pc 000000000042086c  /data/app/~~vTCHnI0ckZx6db5dck92ZA==/chat.reachout.android-BrdnGAC1KTvzZx8YzUU5Gg==/base.apk!libjingle_peerconnection_so.so (offset 0x652e000) (BuildId: 70ca83c0b27c0940)
    #02 pc 0000000000420eb0  /data/app/~~vTCHnI0ckZx6db5dck92ZA==/chat.reachout.android-BrdnGAC1KTvzZx8YzUU5Gg==/base.apk!libjingle_peerconnection_so.so (offset 0x652e000) (BuildId: 70ca83c0b27c0940)
    #03 pc 000000000041019c  /data/app/~~vTCHnI0ckZx6db5dck92ZA==/chat.reachout.android-BrdnGAC1KTvzZx8YzUU5Gg==/base.apk!libjingle_peerconnection_so.so (offset 0x652e000) (BuildId: 70ca83c0b27c0940)
    #04 pc 00000000004100ac  /data/app/~~vTCHnI0ckZx6db5dck92ZA==/chat.reachout.android-BrdnGAC1KTvzZx8YzUU5Gg==/base.apk!libjingle_peerconnection_so.so (offset 0x652e000) (BuildId: 70ca83c0b27c0940)
    #05 pc 00000000008117e4  /data/app/~~vTCHnI0ckZx6db5dck92ZA==/chat.reachout.android-BrdnGAC1KTvzZx8YzUU5Gg==/base.apk!libjingle_peerconnection_so.so (offset 0x652e000) (BuildId: 70ca83c0b27c0940)
    #06 pc 000000000043e014  /data/app/~~vTCHnI0ckZx6db5dck92ZA==/chat.reachout.android-BrdnGAC1KTvzZx8YzUU5Gg==/base.apk!libjingle_peerconnection_so.so (offset 0x652e000) (BuildId: 70ca83c0b27c0940)
    #07 pc 000000000043d454  /data/app/~~v
aliumujib commented 8 months ago

Also we suspect that the error is due to the optional field in this message (we're using GRPC kotlin). I can't find usages of optional fields anywhere else in the models.proto file which might explain why other pieces of functionality works.

aliumujib commented 8 months ago

@davidliu following up.

davidliu commented 7 months ago

Hey, sorry for the delay.

I wonder if it's a compatibility issue here? We're on 3.22.0, and you're using 4.26.0 here. A bump in major version might be the cause here.

GRPC itself seems to not have upgraded to 4.26 either, as noted in https://github.com/grpc/grpc-java/issues/11015

Can you try downgrading to 3.22 (or 3.25.1, which is what grpc uses)?

ashifali3147 commented 4 months ago

Getting the same error when i am using below code

configurations { configureEach { resolutionStrategy { force group: 'com.google.protobuf', name: 'protobuf-javalite', version: '3.10.0' } } }

for some reason i have to use this line because one of libraries only worked on protobuf-javalite:3.10.0 .

davidliu commented 4 months ago

@ashifali3147 Can you provide the dependency tree (run ./gradlew androidDependencies)?

ashifali3147 commented 4 months ago

@davidliu

+--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.0@jar +--- junit:junit:4.13.2@jar +--- androidx.databinding:databinding-adapters:8.3.1@aar +--- androidx.databinding:databinding-ktx:8.3.1@aar +--- androidx.databinding:databinding-runtime:8.3.1@aar +--- androidx.databinding:viewbinding:8.3.1@aar +--- androidx.databinding:databinding-common:8.3.1@jar +--- androidx.navigation:navigation-common:2.7.7@aar +--- androidx.navigation:navigation-common-ktx:2.7.7@aar +--- androidx.navigation:navigation-runtime:2.7.7@aar +--- androidx.navigation:navigation-runtime-ktx:2.7.7@aar +--- androidx.navigation:navigation-fragment:2.7.7@aar +--- androidx.navigation:navigation-fragment-ktx:2.7.7@aar +--- androidx.navigation:navigation-ui-ktx:2.7.7@aar +--- androidx.navigation:navigation-ui:2.7.7@aar +--- com.google.android.material:material:1.11.0@aar +--- com.google.firebase:firebase-inappmessaging-display:20.4.2@aar +--- com.google.firebase:firebase-messaging:23.4.1@aar +--- com.google.firebase:firebase-inappmessaging:20.4.2@aar +--- com.google.firebase:firebase-installations:17.2.0@aar +--- com.google.firebase:firebase-common-ktx:20.4.2@aar +--- io.livekit:livekit-android:2.5.0@aar +--- com.squareup.okhttp3:okhttp:4.12.0@jar +--- androidx.constraintlayout:constraintlayout:2.1.4@aar +--- androidx.constraintlayout:constraintlayout:2.1.4@aar +--- androidx.appcompat:appcompat-resources:1.6.1@aar +--- androidx.appcompat:appcompat:1.6.1@aar +--- androidx.appcompat:appcompat:1.6.1@aar +--- androidx.viewpager2:viewpager2:1.0.0@aar +--- androidx.legacy:legacy-support-v4:1.0.0@aar +--- com.github.bumptech.glide:glide:4.11.0@aar +--- com.google.firebase:firebase-common:20.4.2@aar +--- com.google.firebase:firebase-iid-interop:17.1.0@aar +--- com.google.android.gms:play-services-base:18.0.1@aar +--- com.google.android.gms:play-services-cloud-messaging:17.1.0@aar +--- com.google.android.gms:play-services-stats:17.0.2@aar +--- com.google.firebase:firebase-abt:21.1.1@aar +--- com.google.firebase:firebase-measurement-connector:19.0.0@aar +--- com.google.firebase:firebase-installations-interop:17.1.1@aar +--- androidx.emoji2:emoji2-views-helper:1.2.0@aar +--- androidx.emoji2:emoji2:1.2.0@aar +--- androidx.camera:camera-lifecycle:1.3.4@aar +--- androidx.camera:camera-camera2:1.3.4@aar +--- androidx.camera:camera-core:1.3.4@aar +--- androidx.browser:browser:1.0.0@aar +--- androidx.legacy:legacy-support-core-ui:1.0.0@aar +--- androidx.drawerlayout:drawerlayout:1.1.1@aar +--- androidx.coordinatorlayout:coordinatorlayout:1.1.0@aar +--- androidx.dynamicanimation:dynamicanimation:1.0.0@aar +--- androidx.vectordrawable:vectordrawable-animated:1.1.0@aar +--- androidx.vectordrawable:vectordrawable:1.1.0@aar +--- com.github.lisawray.groupie:groupie-viewbinding:2.10.1@aar +--- com.github.lisawray.groupie:groupie:2.10.1@aar +--- androidx.recyclerview:recyclerview:1.2.1@aar +--- androidx.recyclerview:recyclerview:1.2.1@aar +--- androidx.viewpager:viewpager:1.0.0@aar +--- androidx.legacy:legacy-support-core-utils:1.0.0@aar +--- androidx.loader:loader:1.0.0@aar +--- androidx.slidingpanelayout:slidingpanelayout:1.2.0@aar +--- androidx.slidingpanelayout:slidingpanelayout:1.2.0@aar +--- androidx.customview:customview:1.1.0@aar +--- androidx.media:media:1.0.0@aar +--- androidx.fragment:fragment-ktx:1.6.2@aar +--- androidx.activity:activity-ktx:1.8.0@aar +--- androidx.core:core-ktx:1.13.1@aar +--- androidx.swiperefreshlayout:swiperefreshlayout:1.0.0@aar +--- androidx.asynclayoutinflater:asynclayoutinflater:1.0.0@aar +--- androidx.transition:transition:1.4.1@aar +--- androidx.window:window:1.0.0@aar +--- androidx.core:core:1.13.1@aar +--- androidx.core:core:1.13.1@aar +--- androidx.savedstate:savedstate-ktx:1.2.1@aar +--- androidx.savedstate:savedstate:1.2.1@aar +--- androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.3@aar +--- androidx.lifecycle:lifecycle-common-jvm:2.8.3@jar +--- androidx.lifecycle:lifecycle-viewmodel:2.8.3@aar +--- androidx.lifecycle:lifecycle-viewmodel-android:2.8.3@aar +--- androidx.lifecycle:lifecycle-runtime-ktx-android:2.8.3@aar +--- androidx.lifecycle:lifecycle-livedata-core-ktx:2.8.3@aar +--- androidx.lifecycle:lifecycle-livedata-core:2.8.3@aar +--- androidx.lifecycle:lifecycle-runtime-android:2.8.3@aar +--- androidx.lifecycle:lifecycle-service:2.8.3@aar +--- androidx.lifecycle:lifecycle-livedata:2.8.3@aar +--- androidx.lifecycle:lifecycle-livedata:2.8.3@aar +--- androidx.lifecycle:lifecycle-process:2.8.3@aar +--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.8.3@aar +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3@jar +--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.3@jar +--- org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.7.3@jar +--- com.google.android.gms:play-services-tasks:18.0.2@aar +--- com.google.android.gms:play-services-basement:18.1.0@aar +--- androidx.fragment:fragment:1.6.2@aar +--- androidx.fragment:fragment:1.6.2@aar +--- androidx.activity:activity:1.8.0@aar +--- com.github.ajalt:timberkt:1.5.1@aar +--- org.jetbrains.kotlin:kotlin-android-extensions-runtime:1.9.0@jar +--- com.github.davidliu:audioswitch:89582c47c9a04c62f90aa5e57251af4800a62c9a@aar +--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.20@jar +--- androidx.annotation:annotation-experimental:1.4.0@aar +--- org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.5.0@jar +--- org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.5.0@jar +--- androidx.collection:collection-ktx:1.1.0@jar +--- io.grpc:grpc-okhttp:1.57.2@jar +--- com.squareup.okio:okio-jvm:3.6.0@jar +--- androidx.cursoradapter:cursoradapter:1.0.0@aar +--- androidx.resourceinspection:resourceinspection-annotation:1.0.1@jar +--- androidx.cardview:cardview:1.0.0@aar +--- androidx.profileinstaller:profileinstaller:1.3.1@aar +--- androidx.startup:startup-runtime:1.1.1@aar +--- androidx.tracing:tracing:1.0.0@aar +--- com.google.firebase:firebase-components:17.1.5@aar +--- com.google.firebase:firebase-datatransport:18.2.0@aar +--- com.google.android.datatransport:transport-backend-cct:3.1.9@aar +--- com.google.android.datatransport:transport-runtime:3.1.9@aar +--- com.google.firebase:firebase-encoders-proto:16.0.0@jar +--- com.google.android.datatransport:transport-api:3.1.0@aar +--- com.google.firebase:firebase-encoders-json:18.0.0@aar +--- com.google.firebase:firebase-encoders:17.0.0@jar +--- androidx.versionedparcelable:versionedparcelable:1.1.1@aar +--- androidx.collection:collection:1.1.0@jar +--- androidx.concurrent:concurrent-futures:1.1.0@jar +--- androidx.interpolator:interpolator:1.0.0@aar +--- com.github.bumptech.glide:gifdecoder:4.11.0@aar +--- androidx.exifinterface:exifinterface:1.3.2@aar +--- androidx.arch.core:core-runtime:2.2.0@aar +--- androidx.arch.core:core-common:2.2.0@jar +--- androidx.documentfile:documentfile:1.0.0@aar +--- androidx.localbroadcastmanager:localbroadcastmanager:1.0.0@aar +--- androidx.print:print:1.0.0@aar +--- androidx.annotation:annotation-jvm:1.8.0@jar +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.20@jar +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.20@jar +--- io.grpc:grpc-core:1.57.2@jar +--- com.google.code.gson:gson:2.11.0@jar +--- org.whispersystems:signal-protocol-java:2.8.1@jar +--- org.hamcrest:hamcrest-core:1.3@jar +--- io.grpc:grpc-stub:1.57.2@jar +--- io.grpc:grpc-protobuf-lite:1.57.2@jar +--- io.grpc:grpc-context:1.57.2@jar +--- io.grpc:grpc-api:1.57.2@jar +--- com.google.guava:guava:32.0.1-android@jar +--- com.google.errorprone:error_prone_annotations:2.27.0@jar +--- androidx.constraintlayout:constraintlayout-core:1.0.4@jar +--- com.google.auto.value:auto-value-annotations:1.8.1@jar +--- com.google.dagger:dagger:2.46@jar +--- com.google.firebase:firebase-annotations:16.2.0@jar +--- javax.inject:javax.inject:1@jar +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava@jar +--- com.google.firebase:protolite-well-known-types:18.0.0@aar +--- com.google.protobuf:protobuf-javalite:3.22.3@jar +--- javax.sip:android-jain-sip-ri:1.3.0-91@jar +--- com.vdurmont:semver4j:3.1.0@jar +--- io.github.webrtc-sdk:android-prefixed:125.6422.02@aar +--- com.jakewharton.timber:timber:4.7.0@aar +--- org.whispersystems:curve25519-java:0.5.0@jar +--- org.jetbrains:annotations:23.0.0@jar +--- com.github.bumptech.glide:disklrucache:4.11.0@jar +--- com.github.bumptech.glide:annotations:4.11.0@jar +--- io.reactivex.rxjava2:rxandroid:2.0.2@aar +--- io.reactivex.rxjava2:rxjava:2.1.14@jar +--- io.perfmark:perfmark-api:0.26.0@jar +--- com.google.code.findbugs:jsr305:3.0.2@jar +--- org.reactivestreams:reactive-streams:1.0.2@jar +--- com.google.android:annotations:4.1.1.4@jar +--- org.codehaus.mojo:animal-sniffer-annotations:1.23@jar +--- com.google.guava:failureaccess:1.0.1@jar +--- org.checkerframework:checker-qual:3.33.0@jar --- com.google.j2objc:j2objc-annotations:2.8@jar