1

I am working on an Android project that uses multiple Firebase libraries, which have been functioning without any issues. However, I recently attempted to implement Firebase In-App Messaging, and this has led to a build failure with an error indicating a "duplicate protobuf class".

Error Message:

Duplicate class com.google.protobuf.AbstractMessageLite found in modules jetified-protobuf-java-2.5.0 (com.google.protobuf:protobuf-java:2.5.0) and jetified-protobuf-javalite-3.22.3 (com.google.protobuf:protobuf-javalite:3.22.3)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder found in modules jetified-protobuf-java-2.5.0 (com.google.protobuf:protobuf-java:2.5.0) and jetified-protobuf-javalite-3.22.3 (com.google.protobuf:protobuf-javalite:3.22.3)
Duplicate class com.google.protobuf.AbstractMessageLite$Builder$LimitedInputStream found in modules jetified-protobuf-java-2.5.0 (com.google.protobuf:protobuf-java:2.5.0) and jetified-protobuf-javalite-3.22.3 (com.google.protobuf:protobuf-javalite:3.22.3)
Duplicate class com.google.protobuf.AbstractParser found in modules jetified-protobuf-java-2.5.0 (com.google.protobuf:protobuf-java:2.5.0) and jetified-protobuf-javalite-3.22.3 (com.google.protobuf:protobuf-javalite:3.22.3)
Duplicate class com.google.protobuf.ByteString found in modules jetified-protobuf-java-2.5.0 (com.google.protobuf:protobuf-java:2.5.0) and jetified-protobuf-javalite-3.22.3 (com.google.protobuf:protobuf-javalite:3.22.3)
Duplicate class com.google.protobuf.ByteString$1 found in modules jetified-protobuf-java-2.5.0 (com.google.protobuf:protobuf-java:2.5.0) and jetified-protobuf-javalite-3.22.3 (com.google.protobuf:protobuf-javalite:3.22.3)
Duplicate class com.google.protobuf.ByteString$ByteIterator found in modules jetified-protobuf-java-2.5.0 (com.google.protobuf:protobuf-java:2.5.0) and jetified-protobuf-javalite-3.22.3 (com.google.protobuf:protobuf-javalite:3.22.3)
Duplicate class com.google.protobuf.ByteString$CodedBuilder found in modules jetified-protobuf-java-2.5.0 (com.google.protobuf:protobuf-java:2.5.0) and jetified-protobuf-javalite-3.22.3 (com.google.protobuf:protobuf-javalite:3.22.3)

Trying to add this dependency implementation("com.google.firebase:firebase-inappmessaging-display:21.0.0")

Attempted Solutions:

  1. I tried excluding the protobuf classes in my Gradle file:
implementation("com.google.firebase:firebase-inappmessaging-display:21.0.0") {  
    exclude group: 'com.google.protobuf' 
}
  1. Also tried old version for that.
  2. I incorporated the Firebase Bill of Materials (BOM) to manage versions automatically:
implementation platform('com.google.firebase:firebase-bom:xx.x.x')
implementation 'com.google.firebase:firebase-inappmessaging-display'

Despite these attempts, the problem persists. My project's relevant dependencies are as follows:

dependencies {
        classpath 'com.android.tools.build:gradle:8.0.2'
        classpath 'com.google.gms:google-services:4.3.15'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
        classpath 'com.google.firebase:perf-plugin:1.3.4'  // Performance Monitoring plugin
    }
dependencies {
    implementation('com.google.firebase:firebase-messaging:22.0.0') {
        exclude group: 'com.google.firebase', module: 'firebase-analytics'
        exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
    }
    implementation 'com.google.firebase:firebase-analytics:20.1.2'
    implementation 'com.google.firebase:firebase-auth:21.0.1'
    implementation 'com.google.firebase:firebase-core:20.1.2'
    implementation 'com.google.firebase:firebase-crashlytics:18.2.1'
    implementation 'com.google.firebase:firebase-iid:21.1.0'
    implementation 'com.firebase:firebase-jobdispatcher:0.8.6'
    implementation 'com.google.firebase:firebase-perf:19.0.1'
    implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
    implementation 'com.google.firebase:firebase-appcheck-playintegrity:17.0.1'
}

Question: How can I resolve the duplicate class issue caused by protobuf when adding Firebase In-App Messaging to my project? Is there a specific configuration or version management technique I should follow?

Thank you in advance for your help!

1

1 Answer 1

1

After much debugging, I finally got a solution for that. The conflict is for

org.whispersystems:signal-protocol-java:2.6.2

This library using protobuf Java, and it is causing the duplicate class error. After updating this to the latest version, my Gradle build was successful. Also, I want to mention one more thing: you may go through app crashes because of protobuf library conflicts.

For that, you can use this solution:

configurations {
configureEach {
    resolutionStrategy {
        force group: 'com.google.protobuf', name: 'protobuf-javalite', version: '3.10.0'
    } 
}}

you can refer this link protobuf-crash

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.