【问题标题】:Duplicate class error when using Firestore and Google Speech to Text使用 Firestore 和 Google Speech to Text 时出现重复的类错误
【发布时间】:2020-05-18 05:39:40
【问题描述】:

尝试使用 Firestore 和 Google Speech to Text 库构建项目时,我收到“重复类”错误。据我了解,这是由于两个库都引入了 proto 库。排除会产生运行时错误。如何解决重复问题?

这是错误(串联,还有数百行):

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) 

【问题讨论】:

    标签: android google-cloud-firestore build.gradle google-speech-api


    【解决方案1】:

    我想通了。 Google Speech-to-Text Java 库目前不支持 Android,因此出现错误。据我了解,protobuf-java(Google Speech-to-Text 使用)用于桌面解决方案,protobuf-lite(Firestore 使用)用于移动解决方案。排除任何一个模块都会破坏它们各自的依赖项。

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

    我采取的步骤:

    1. 将每个有冲突的 .jar 复制到一个新文件夹中(不管在哪里)
    2. 将扩展名更改为 .zip
    3. 将每个 zip 中的内容提取到一个文件夹中。当要求覆盖时,请这样做。
    4. 重要提示:确保您提取的最后一个 zip 是 protolite-well-known-types 和 protobuf-javalite,这将确保 Firestore 具有正确的库。确保它们覆盖所有现有文件。
    5. 压缩文件夹的内容。
    6. 将文件扩展名更改为 .jar
    7. 将新的 .jar 添加到您的 /lib 文件夹中
    8. 从 build.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 Speech-to-Text 库进行任何方法调用时会产生运行时错误。

    到目前为止,我认为没有任何方法可以将 Firebase 与 Google Speech-to-Text 库一起使用,因为 Android 尚不支持 Google Speech-to-Text。

    【讨论】:

    【解决方案2】:

    就我而言,我使用的是DialogFlowFirestore

    使用下面的依赖对我来说就足够了

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

    【讨论】:

    • 虽然它在构建时消除了错误,但如果您使用的是刚刚在此处排除的一些依赖项,您将开始在构建时看到缺少类的错误。唯一的解决方案是手动解决重复并导入jar
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-24
    相关资源
    最近更新 更多