21

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.

rlazo
  • 635
  • 4
  • 14

8 Answers8

14

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.

rlazo
  • 635
  • 4
  • 14
  • 1
    I am currently using `com.google.firebase:firebase-firestore:21.5.0`. As far as I know, this is the latest version, but I still get the error. – Kellin Strook Jul 10 '20 at 16:35
  • Do you also depend in any other of the SDKs in the list? You need to update all of them. – rlazo Jul 10 '20 at 18:45
  • No. Only `com.google.firebase:firebase-firestore:21.5.0`. I ended up downgrading to previous version. – Kellin Strook Jul 11 '20 at 09:11
  • Most likely other non-firebase dependencies in your app are pulling the `protobuf-lite` dependency. Check here on how to get the dependency tree for your app https://stackoverflow.com/questions/21645071/using-gradle-to-find-dependency-tree – rlazo Jul 13 '20 at 16:26
2

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.

  • You're right, latest crypto libraries don't depend on protobuf anymore https://dl.google.com/android/maven2/androidx/security/security-crypto/1.0.0-rc03/security-crypto-1.0.0-rc03.pom – rlazo Aug 28 '20 at 18:18
2

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

Heath Borders
  • 30,998
  • 16
  • 147
  • 256
2

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.

matox
  • 885
  • 11
  • 27
2

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.

1

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'
Yashovardhan99
  • 887
  • 11
  • 26
1

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

Gilbert Parreno
  • 107
  • 1
  • 4
0

The easiest solution just add the boom library for firebase and remove library version for libraries it will resolve the library conflicts

 // Import the Firebase BoM
  implementation platform('com.google.firebase:firebase-bom:29.3.1')

 // When using the BoM, you don't specify versions in Firebase library dependencies

  // Declare the dependency for the Firebase SDK for Google Analytics
  implementation 'com.google.firebase:firebase-analytics'