使用FiRestore和Google语音转文本时出现重复类错误 [英] Duplicate class error when using Firestore and Google Speech to Text

查看:64
本文介绍了使用FiRestore和Google语音转文本时出现重复类错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用FiRestore和Google Speech to Text库构建项目时,我收到"重复类"错误。据我所知,这是因为这两个库都引入了原型库。排除会产生运行时错误。如何解决重复问题?

以下是错误(连接在一起,还有数百行):

Duplicate class com.google.api.Advice found in modules jetified-proto-google-common-protos-1.17.0.jar (com.google.api.grpc:proto-google-common-protos:1.17.0) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.api.Advice$1 found in modules jetified-proto-google-common-protos-1.17.0.jar (com.google.api.grpc:proto-google-common-protos:1.17.0) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)
Duplicate class com.google.api.Advice$Builder found in modules jetified-proto-google-common-protos-1.17.0.jar (com.google.api.grpc:proto-google-common-protos:1.17.0) and jetified-protolite-well-known-types-17.0.0-runtime.jar (com.google.firebase:protolite-well-known-types:17.0.0)

以下是我的依赖项:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.google.firebase:firebase-analytics:17.4.1'
    implementation 'com.firebaseui:firebase-ui-auth:6.2.0'
    implementation 'com.google.firebase:firebase-firestore:21.4.3'

    // add these dependencies for the speech client
    implementation 'io.grpc:grpc-okhttp:1.29.0'
    implementation 'com.google.cloud:google-cloud-speech:1.23.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

如果我添加以下排除项,则编译可以正常工作,但随后我会收到FiRestore的运行时错误:

configurations {
    implementation.exclude module:'protolite-well-known-types'
    implementation.exclude module:'protobuf-javalite'
}

以下是运行时FiRestore错误:

java.lang.RuntimeException: Internal error in Cloud Firestore (21.4.3).
        at com.google.firebase.firestore.util.AsyncQueue.lambda$panic$3(com.google.firebase:firebase-firestore@@21.4.3:534)
        at com.google.firebase.firestore.util.AsyncQueue$$Lambda$3.run(Unknown Source:2)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.ExceptionInInitializerError
        at com.google.firestore.v1.ListenRequest.getDefaultInstance(com.google.firebase:firebase-firestore@@21.4.3:915)
        at com.google.firestore.v1.FirestoreGrpc.getListenMethod(com.google.firebase:firebase-firestore@@21.4.3:408)
        at com.google.firebase.firestore.remote.WatchStream.<init>(com.google.firebase:firebase-firestore@@21.4.3:61)
        at com.google.firebase.firestore.remote.Datastore.createWatchStream(com.google.firebase:firebase-firestore@@21.4.3:115)
        at com.google.firebase.firestore.remote.RemoteStore.<init>(com.google.firebase:firebase-firestore@@21.4.3:167)
        at com.google.firebase.firestore.core.FirestoreClient.initialize(com.google.firebase:firebase-firestore@@21.4.3:281)
        at com.google.firebase.firestore.core.FirestoreClient.lambda$new$0(com.google.firebase:firebase-firestore@@21.4.3:109)
        at com.google.firebase.firestore.core.FirestoreClient$$Lambda$1.run(Unknown Source:8)
        at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$2(com.google.firebase:firebase-firestore@@21.4.3:436)
        at com.google.firebase.firestore.util.AsyncQueue$$Lambda$2.call(Unknown Source:2)
        at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.lambda$executeAndReportResult$1(com.google.firebase:firebase-firestore@@21.4.3:322)
        at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$$Lambda$2.run(Unknown Source:4)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$DelayedStartFactory.run(com.google.firebase:firebase-firestore@@21.4.3:229)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.RuntimeException: Unable to get message info for com.google.firestore.v1.ListenRequest
        at com.google.protobuf.GeneratedMessageInfoFactory.messageInfoFor(GeneratedMessageInfoFactory.java:62)
        at com.google.protobuf.ManifestSchemaFactory$CompositeMessageInfoFactory.messageInfoFor(ManifestSchemaFactory.java:143)
        at com.google.protobuf.ManifestSchemaFactory.createSchema(ManifestSchemaFactory.java:55)
        at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:93)
        at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:107)
        at com.google.protobuf.GeneratedMessageLite.makeImmutable(GeneratedMessageLite.java:171)
        at com.google.firestore.v1.ListenRequest.<clinit>(com.google.firebase:firebase-firestore@@21.4.3:911)
        at com.google.firestore.v1.ListenRequest.getDefaultInstance(com.google.firebase:firebase-firestore@@21.4.3:915) 
        at com.google.firestore.v1.FirestoreGrpc.getListenMethod(com.google.firebase:firebase-firestore@@21.4.3:408) 
        at com.google.firebase.firestore.remote.WatchStream.<init>(com.google.firebase:firebase-firestore@@21.4.3:61) 
        at com.google.firebase.firestore.remote.Datastore.createWatchStream(com.google.firebase:firebase-firestore@@21.4.3:115) 
        at com.google.firebase.firestore.remote.RemoteStore.<init>(com.google.firebase:firebase-firestore@@21.4.3:167) 
        at com.google.firebase.firestore.core.FirestoreClient.initialize(com.google.firebase:firebase-firestore@@21.4.3:281) 
        at com.google.firebase.firestore.core.FirestoreClient.lambda$new$0(com.google.firebase:firebase-firestore@@21.4.3:109) 
        at com.google.firebase.firestore.core.FirestoreClient$$Lambda$1.run(Unknown Source:8) 
        at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$2(com.google.firebase:firebase-firestore@@21.4.3:436) 
        at com.google.firebase.firestore.util.AsyncQueue$$Lambda$2.call(Unknown Source:2) 
        at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.lambda$executeAndReportResult$1(com.google.firebase:firebase-firestore@@21.4.3:322) 
        at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$$Lambda$2.run(Unknown Source:4) 
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$DelayedStartFactory.run(com.google.firebase:firebase-firestore@@21.4.3:229) 
        at java.lang.Thread.run(Thread.java:764) 
     Caused by: java.lang.UnsupportedOperationException
        at com.google.firestore.v1.ListenRequest.dynamicMethod(com.google.firebase:firebase-firestore@@21.4.3:903)
        at com.google.protobuf.GeneratedMessageLite.dynamicMethod(GeneratedMessageLite.java:252)
        at com.google.protobuf.GeneratedMessageLite.buildMessageInfo(GeneratedMessageLite.java:280)
        at com.google.protobuf.GeneratedMessageInfoFactory.messageInfoFor(GeneratedMessageInfoFactory.java:60)
        at com.google.protobuf.ManifestSchemaFactory$CompositeMessageInfoFactory.messageInfoFor(ManifestSchemaFactory.java:143) 
        at com.google.protobuf.ManifestSchemaFactory.createSchema(ManifestSchemaFactory.java:55) 
        at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:93) 
        at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:107) 
        at com.google.protobuf.GeneratedMessageLite.makeImmutable(GeneratedMessageLite.java:171) 
        at com.google.firestore.v1.ListenRequest.<clinit>(com.google.firebase:firebase-firestore@@21.4.3:911) 
        at com.google.firestore.v1.ListenRequest.getDefaultInstance(com.google.firebase:firebase-firestore@@21.4.3:915) 
        at com.google.firestore.v1.FirestoreGrpc.getListenMethod(com.google.firebase:firebase-firestore@@21.4.3:408) 
        at com.google.firebase.firestore.remote.WatchStream.<init>(com.google.firebase:firebase-firestore@@21.4.3:61) 
        at com.google.firebase.firestore.remote.Datastore.createWatchStream(com.google.firebase:firebase-firestore@@21.4.3:115) 
        at com.google.firebase.firestore.remote.RemoteStore.<init>(com.google.firebase:firebase-firestore@@21.4.3:167) 
        at com.google.firebase.firestore.core.FirestoreClient.initialize(com.google.firebase:firebase-firestore@@21.4.3:281) 
        at com.google.firebase.firestore.core.FirestoreClient.lambda$new$0(com.google.firebase:firebase-firestore@@21.4.3:109) 
        at com.google.firebase.firestore.core.FirestoreClient$$Lambda$1.run(Unknown Source:8) 
        at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$2(com.google.firebase:firebase-firestore@@21.4.3:436) 
        at com.google.firebase.firestore.util.AsyncQueue$$Lambda$2.call(Unknown Source:2) 
        at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.lambda$executeAndReportResult$1(com.google.firebase:firebase-firestore@@21.4.3:322) 
        at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$$Lambda$2.run(Unknown Source:4) 
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$DelayedStartFactory.run(com.google.firebase:firebase-firestore@@21.4.3:229) 
        at java.lang.Thread.run(Thread.java:764) 

推荐答案

我已经弄清楚了。Google Speech-to-Text Java库目前不支持Android,因此出现错误。据我所知,协议buf-java(由Google语音转文本使用)用于桌面解决方案,协议buf-lite(由Firestore使用)用于移动解决方案。排除任一模块将中断其各自的从属模块。

我的解决办法是创建我自己的.jar,其中包含来自两者的类,包括我的项目中的.jar,然后从build.gradle中它们的依赖项中排除模块。这将确保我的项目中有正确的模块,而且我将只有一个类副本。

我采取的步骤:

  1. 将每个有冲突的.jar复制到新文件夹(与位置无关)
  2. 将扩展名更改为.zip
  3. 将每个zip中的内容解压缩到单个文件夹。当要求覆盖时,请执行此操作。
  4. 重要提示:确保您解压缩的最后一个压缩是protite-熟知-类型和Protobuf-javalite,这将确保Firestore拥有正确的库。请确保它们覆盖所有现有文件。
  5. 压缩文件夹内容。
  6. 将文件扩展名更改为.jar
  7. 将新的.jar添加到/lib文件夹
  8. 从生成中的从属模块中排除模块。gradle
   implementation('com.google.firebase:firebase-firestore:21.4.3') {
        exclude module: 'protolite-well-known-types'
        exclude module: 'protobuf-javalite'
        exclude module: 'protobuf-java'
        exclude module: 'protobuf-java-util'
    }

    implementation('com.google.cloud:google-cloud-speech:1.23.0') {
        exclude module: 'protolite-well-known-types'
        exclude module: 'protobuf-javalite'
        exclude module: 'proto-google-common-protos'
        exclude module: 'protobuf-java'
        exclude module: 'protobuf-java-util'
    }

编辑:

这不能完全工作。它允许项目编译并调用Firestore来运行,但是在尝试使用Google语音到文本库进行任何方法调用时会产生运行时错误。

到目前为止,我认为没有任何方法可以将Firebase与Google语音到文本库一起使用,因为Android还不支持Google语音到文本。

这篇关于使用FiRestore和Google语音转文本时出现重复类错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆