Updated firebase dependency and got duplicated protobuf classes error

被刻印的时光 ゝ 提交于 2021-02-20 05:38:04

问题


I'm getting this error after updating one of my firebase SDKs

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
  java.lang.RuntimeException: Duplicate class com.google.protobuf.AbstractMessageLite found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-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 jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractParser found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.AbstractProtobufList found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.BooleanArrayList found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
  Duplicate class com.google.protobuf.ByteBufferWriter found in modules jetified-protobuf-javalite-3.11.0.jar (com.google.protobuf:protobuf-javalite:3.11.0) and jetified-protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)
...

My app now depends on protobuf-lite and protobuf-javalite, which triggers the duplicate class error.


回答1:


Recently, Firebase Android has migrated from depending on the old protobuf-lite to depend on protobuf-javalite (github issue | PR implementing the change).

You need to update all the firebase SDKs affected by this change together, otherwise the old SDKs will pull the wrong dependency into your app.

Here is the list of affected SDKs and their versions supporting protobuf-javalite

- com.google.firebase:firebase-firestore:21.5.0
- com.google.firebase:firebase-inappmessaging:19.1.0
- com.google.firebase:firebase-inappmessaging-display:19.1.0
- com.google.firebase:firebase-config:19.2.0
- com.google.firebase:firebase-abt:19.1.0
- com.google.firebase:firebase-perf:19.0.8

EDIT: Added firebase-perf to the list, as it transitively depends on config and also needs to be updated.




回答2:


For me I just downgraded my com.google.firebase:firebase-firestore:21.5.0 -> com.google.firebase:firebase-firestore:21.4.3




回答3:


This burned me because com.google.android.gms:play-services-cast-framework:17.1.0 through at least com.google.android.gms:play-services-cast-framework:19.0.0 transitively depends on com.google.protobuf:protobuf-lite:3.0.1 through its dependency on com.google.android.datatransport:transport-backend-cct:2.0.1 through com.google.android.datatransport:transport-backend-cct:2.1.0.

Someone from Spotify filed an issue about this: https://issuetracker.google.com/issues/161831470




回答4:


try to degrade

implementation 'com.google.firebase:firebase-firestore:21.4.3'
implementation 'com.google.firebase:firebase-config:19.1.4'

It works with

implementation 'androidx.mediarouter:mediarouter:1.1.0'
implementation 'com.google.android.gms:play-services-cast-framework:18.1.0'



回答5:


In my case the problem was androidx.security:security-crypto:1.0.0-alpha02 library that depends on protobuf-lite which conflicts with protobuf-java-lite being used by Firebase. Updating this library helped.

You can check if other libraries depend on conflicting protobuf-lite by calling ./gradlew app:dependencies in Terminal. Then cmd+f and search for proto.




回答6:


I solved this problem by manually searching in the Gradle dependency tree and updating the problematic SDK afterward.

For Android, use this line

gradle app:dependencies > dependency_tree.txt

or if you have a gradle wrapper:

./gradlew app:dependencies > dependency_tree.txt

where app is your project module.

Then manually search for proto for problematic SDK within the dependency_tree.txt file.




回答7:


This error means that you are importing two packages that use Protobuf for your project, one of them has a distribution that's conflicting with the other.
If you encountered this problem on Flutter, you can reconsider the version number of your dependencies in pubspec.yaml, and replace "any" by an exact version number.
For example, under "dependencies:" change:

barcode_scan: any

To:

barcode_scan: ^2.0.0

I hope I helped.



来源:https://stackoverflow.com/questions/62764605/updated-firebase-dependency-and-got-duplicated-protobuf-classes-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!