java.lang.RuntimeException: Duplicate class com.google.protobuf.AbstractMessageLite when adding firebase remote config
Asked Answered
S

3

10

When I am adding com.google.firebase:firebase-config:19.1.0 to use firebase remote config having this issue.

  java.lang.RuntimeException: Duplicate class com.google.protobuf.AbstractMessageLite found in modules protobuf-java-2.5.0.jar (com.google.protobuf:protobuf-java:2.5.0) and protobuf-lite-3.0.1.jar (com.google.protobuf:protobuf-lite:3.0.1)

I have updated both firebase-analytics and google-play-services to latest version. But still the problem exist. But when I changed remote config to older version 18.0.0 or less then its working fine. But I want to use the latest version. My dependencies:

    firebase_analytics       : "com.google.firebase:firebase-analytics:17.2.2",
    fcm                      : "com.google.firebase:firebase-messaging:20.1.0",
    performance              : "com.google.firebase:firebase-perf:19.0.0",
    config                   : "com.google.firebase:firebase-config:19.0.0",

Also tried to exclude below doesn't work:

exclude group: 'com.google.protobuf', module: 'protobuf-lite'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
Swill answered 21/1, 2020 at 10:8 Comment(0)
S
19

Finally, I fixed this issue. First lets understand the issue:

protobuf-java and protobuf-lite are incompatible packages. They both include classes in the com.google.protobuf package. protobuf-java is typically used in packages intended for desktop and server-side use (i.e. regular Java), while protobuf-lite is frequently used in packages that target Android.

Firebase packages depend upon protobuf-lite. Something else in your project must depend on protobuf-java. You can see a tree view of your dependencies by following these instructions: https://stackoverflow.com/a/35235229.

The exclusion is required to resolve the incompatibility, though really you should see if there's an android-specific variant of whatever package you're using that's introducing protobuf-java.

To exclude the duplicate classes that's causing the problem, add the following code into your build.gradle (app module) file:

android {
    ... 

  configurations { 
      implementation.exclude module:'protobuf-lite' 
  }
}
Swill answered 28/1, 2020 at 8:53 Comment(2)
This is making the application crash !!Alienate
Thanks Mate . After spending 5 hours on the issue , I applied your solution and worked for me.Raspy
T
2

try this, add the code in app's build

configurations {
    implementation.exclude module:'protobuf-java'
}
Tellford answered 12/4, 2021 at 12:34 Comment(0)
I
0

The missing classes is a known issue. Full proto and lite proto can't be mixed; they use different generated code. Do not depend on protobuf-java as an implementation dependency, but as a protobuf dependency which will cause gradle-protobuf-plugin to generate code for the .protos.

dependencies {
  ...
  protobuf 'com.google.protobuf:protobuf-java:3.7.1'
}

Note that this solution only really works for an application. If you are a library, it is dangerous because users of your library may then see multiple copied of the generated code for the well-known protos.

Inroad answered 21/1, 2020 at 10:10 Comment(1)
I am not using this dependency anywhere. Would you please clarify what you mean to say.Swill

© 2022 - 2024 — McMap. All rights reserved.