Skip to content

Duplicate class exception with protobuf #4927

Open

Description

@V-Abhilash-1999

[REQUIRED] Step 2: Describe your environment

Android Studio version: Electric Eel | 2022.1.1 Patch 1
Firebase Component: Firestore
Component version: 24.2.1 (BoM: 30.3.0)

[REQUIRED] Step 3: Describe the problem

I am using firebase with the following dependencies

implementation (platform('com.google.firebase:firebase-bom:30.3.0'))
implementation ('com.google.firebase:firebase-analytics-ktx')
implementation ('com.google.firebase:firebase-messaging-ktx')
implementation ('com.google.firebase:firebase-firestore-ktx')
implementation ('com.google.firebase:firebase-perf-ktx')

I have created a SDK which uses protobuf java. Since the firebase uses protobuf java lite. It results in duplicate class exception.

I cannot exclude protobuf from my SDK dependency because that would cause a java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/protobuf/GeneratedMessageV3; exception.

If I exclude protobuf from firebase. It still shows duplicate class exception because it has a nested dependency.
com.google.firebase:protolite-well-known-types:18.0.0@aar

They have created a package with com.google.protobuf inside this module.

I cannot exclude this dependency, because it would result in same NoClassDefFoundError.

Activity

  1. google-oss-bot commented on Apr 24, 2023

    @google-oss-bot
    Collaborator

    I found a few problems with this issue:

    • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
    • This issue does not seem to follow the issue template. Make sure you provide all the required information.
  2. argzdev commented on Apr 25, 2023

    @argzdev
    Contributor

    Hi @V-Abhilash-1999, thanks for reaching out to us. I noticed that you're using an older version of the SDK. I don't think this would make any difference but could you try updating to the latest version of Firestore version 24.5.0 (BoM: 31.5.0) and see if this resolves the issue? We usually advise this to avoid issues or fixes that have been made in the most recent versions.

    May I know which specific library of protobuf java and version are you using? Also any chance you could share with us a minimal reproducible example of your issue? It'll help us a lot. Thanks!

  3. wu-hui commented on Apr 26, 2023

    @wu-hui
    Contributor

    Is it at all possible for you to depend on protobuf-lite?

  4. V-Abhilash-1999 commented on Apr 26, 2023

    @V-Abhilash-1999
    Author

    I am sorry. I was a bit busy.
    I could depend on protobuf-javalite, but that would remove JSON support (JSON to proto conversion).
    So I was looking for a way to keep using protobuf-java.

    Also on an unrelated note,

    I tried to convert my library to protobuf-javalite, while testing I came across a issue, where my library uses protobuf-javalite and Application uses protobuf-java. In this case, If I were to exclude protobuf-javalite, it results in java.lang.VerifyError: Verifier rejected class on google.protobuf.FloatValue.

    Upon further investigating, i came across this issue
    #2165

    Is migrating to protobuf-javalite the only solution for this?

  5. wu-hui commented on Apr 27, 2023

    @wu-hui
    Contributor

    It seems like you are depending on protobuf-java directly. In this case, what you could do is to pulling protobuf-java and rename its package. Not ideal, but if you really want to keep the protobuf to json feature, this is the only way I am aware of.

  6. V-Abhilash-1999 commented on Apr 28, 2023

    @V-Abhilash-1999
    Author

    Why is there a verify error when excluding protobuf-javalite in firebase? I am also facing a similar issue (if I am using FloatValue in my proto). How to avoid it?

  7. HlebMaliborski commented on Jan 3, 2025

    @HlebMaliborski

    Hi! Any update on this?

  8. yurihondo commented on Jun 26, 2026

    @yurihondo

    Hi, I'm facing the same issue. Are there any updates on this?

  9. dconeybe commented on Oct 8, 2026

    @dconeybe
    Contributor

    Update: Firebase Android BoM version 35.0.0 (released October 07, 2026) includes #8580 which upgrades the gRPC and protobuf dependencies to their latest versions. This may fix the problems reported in this issue. Please try upgrading and report your findings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions