3

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 of

com.google.firebase:protolite-well-known-types:18.0.0@aar

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

Is there any way to avoid Duplicate Class Exception without any crash?

Abhilash
  • 61
  • 5

1 Answers1

0

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

I have solved this issue by adding following codes in app/build.gradle

android {
  ...
  configurations {
    implementation.exclude module:'protobuf-java'
  }
}
Baby Bear
  • 11
  • 3