排除等级无效。 目前,我在Android应用程序中使用Firebase Firestore,Firestore在内部使用“ protobuf-lite”,而该库与另一个使用“ protobuf-java”的库发生冲突,这会导致重复的gradle错误并构建失败。
Duplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-java-3.0.0.jar (com.google.protobuf:protobuf-java:3.0.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules protobuf-java-3.0.0.jar (com.google.protobuf:protobuf-java:3.0.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream found in modules protobuf-java-3.0.0.jar (com.google.protobuf:protobuf-java:3.0.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractParser found in modules protobuf-java-3.0.0.jar (com.google.protobuf:protobuf-java:3.0.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.AbstractProtobufList found in modules protobuf-java-3.0.0.jar (com.google.protobuf:protobuf-java:3.0.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
Duplicate class com.google.protobuf.Any found in modules classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) and protobuf-java-3.0.0.jar (com.google.protobuf:protobuf-java:3.0.0)
Duplicate class com.google.protobuf.Any$1 found in modules classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) and protobuf-java-3.0.0.jar (com.google.protobuf:protobuf-java:3.0.0)
Duplicate class com.google.protobuf.Any$Builder found in modules classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) and protobuf-java-3.0.0.jar (com.google.protobuf:protobuf-java:3.0.0)
Duplicate class com.google.protobuf.AnyProto found in modules classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) and protobuf-java-3.0.0.jar (com.google.protobuf:protobuf-java:3.0.0)
Duplicate class com.google.protobuf.Api found in modules classes.jar (com.google.firebase:protolite-well-known-types:16.0.1) and protobuf-java-3.0.0.jar (com.google.protobuf:protobuf-java:3.0.0)
我在Firestore实现中添加了一条规则,以排除与其他库冲突的这些模块
implementation('com.google.firebase:firebase-firestore:20.1.0', {
exclude group: 'com.google.firebase', module:'protolite-well-known-types'
exclude group: 'com.google.firebase', module:'protobuf-lite'
exclude group: 'com.google.protobuf', module:'protobuf-lite'
})
现在,项目成功构建并且应用程序运行,但是当我执行任何Firestore操作时,应用程序崩溃,这意味着它们不仅从应用程序模块中排除在Firestore库本身之外。
java.lang.RuntimeException: Internal error in Firestore (20.1.0).
at com.google.firebase.firestore.util.AsyncQueue.lambda$panic$5(com.google.firebase:firebase-firestore@@20.1.0:379)
at com.google.firebase.firestore.util.AsyncQueue$$Lambda$5.run(com.google.firebase:firebase-firestore@@20.1.0)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:241)
at android.app.ActivityThread.main(ActivityThread.java:6274)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.VerifyError: Verifier rejected class com.google.firestore.v1.WriteResponse: void com.google.firestore.v1.WriteResponse.mergeCommitTime(com.google.protobuf.Timestamp) failed to verify: void com.google.firestore.v1.WriteResponse.mergeCommitTime(com.google.protobuf.Timestamp): [0x10] register v3 has type Precise Reference: com.google.protobuf.Timestamp but expected Reference: com.google.protobuf.GeneratedMessageLiteVerifier rejected class com.google.firestore.v1.WriteResponse: java.lang.Object com.google.firestore.v1.WriteResponse.dynamicMethod(com.google.protobuf.GeneratedMessageLite$MethodToInvoke, java.lang.Object, java.lang.Object) failed to verify: java.lang.Object com.google.firestore.v1.WriteResponse.dynamicMethod(com.google.protobuf.GeneratedMessageLite$MethodToInvoke, java.lang.Object, java.lang.Object): [0x73] register v5 has type Precise Reference: com.google.protobuf.Timestamp but expected Reference: com.google.protobuf.GeneratedMessageLite (declaration of 'com.google.firestore.v1.WriteResponse' appears in /data/app/com.demo.myapplication-2/base.apk)
at com.google.firestore.v1.WriteResponse.getDefaultInstance(com.google.firebase:firebase-firestore@@20.1.0:1012)
at com.google.firestore.v1.FirestoreGrpc.getWriteMethod(com.google.firebase:firebase-firestore@@20.1.0:379)
at com.google.firebase.firestore.remote.WriteStream.<init>(com.google.firebase:firebase-firestore@@20.1.0:74)
at com.google.firebase.firestore.remote.Datastore.createWriteStream(com.google.firebase:firebase-firestore@@20.1.0:104)
at com.google.firebase.firestore.remote.RemoteStore.<init>(com.google.firebase:firebase-firestore@@20.1.0:186)
at com.google.firebase.firestore.core.FirestoreClient.initialize(com.google.firebase:firebase-firestore@@20.1.0:263)
at com.google.firebase.firestore.core.FirestoreClient.lambda$new$2(com.google.firebase:firebase-firestore@@20.1.0:117)
at com.google.firebase.firestore.core.FirestoreClient$$Lambda$2.run(com.google.firebase:firebase-firestore@@20.1.0)
at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$4(com.google.firebase:firebase-firestore@@20.1.0:311)
at com.google.firebase.firestore.util.AsyncQueue$$Lambda$4.call(com.google.firebase:firebase-firestore@@20.1.0)
at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$3(com.google.firebase:firebase-firestore@@20.1.0:287)
at com.google.firebase.firestore.util.AsyncQueue$$Lambda$3.run(com.google.firebase:firebase-firestore@@20.1.0)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at com.google.firebase.firestore.util.AsyncQueue$DelayedStartFactory.run(com.google.firebase:firebase-firestore@@20.1.0:205)
at java.lang.Thread.run(Thread.java:761)
问题是: 不排除意味着不要将这些模块从Firestore库导入到应用程序模块,而不要将其从Firestore中删除吗? 如果没有,那么如何使它们仅可用于内部Firestore并隐藏在应用程序模块中,以避免任何冲突和重复的类错误。
========更新========== 我解决了这个问题 由于我们无法更改依赖于protolite版本的Firestore内部代码,因此唯一的方法是更改依赖proto-java的其他模块以使用protolite修复此重复错误,并执行此操作 我必须使用protobuf lite编译器从proto文件生成Java类,该java类将生成依赖于protolite库而不是proto-jave的类,现在我可以将Proto-lite库用于Firestore和其他Module以及重复类错误消失了。