firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.26k stars 574 forks source link

Duplicate classes jetified-protolite-well-known-types and protobuf-java #6359

Open CloudLevi opened 1 week ago

CloudLevi commented 1 week ago

[READ] Step 1: Are you in the right place?

Issues filed here should be about bugs in the code in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

When using firebase APIs with com.google.cloud:google-cloud-pubsub, I am not able to build the project due to many duplicate class errors. If I add the following exclusions in the build.gralde, the app is able to run, but firebase services fail immediately:

configurations {
    implementation.exclude module:'proto-google-common-protos'
    implementation.exclude module:'protolite-well-known-types'
    implementation.exclude module:'protobuf-lite'
    implementation.exclude module:'protobuf-javalite'
}

Steps to reproduce:

Try to build the project with firebase APIs and google cloud pubsub.

Relevant Code:

Versions of firebase APIs used:

    implementation platform('com.google.firebase:firebase-bom:33.4.0')
    //firestore integration
    implementation 'com.google.firebase:firebase-firestore'
    //firebase storage (files)
    implementation 'com.google.firebase:firebase-storage'
    //firebase auth
    implementation 'com.google.firebase:firebase-auth'
    //firebase-functions
    implementation 'com.google.firebase:firebase-functions'
    //firebase remote config
    implementation 'com.google.firebase:firebase-config'
    //firebase messaging
    implementation 'com.google.firebase:firebase-messaging'
    implementation("com.google.firebase:firebase-crashlytics")
    implementation("com.google.firebase:firebase-analytics")

Google Cloud PubSub version used:

    implementation platform('com.google.cloud:libraries-bom:26.47.0')
    implementation 'com.google.cloud:google-cloud-pubsub'

Build error output attached in a file: firebase_conflict_error_output.txt

lehcar09 commented 6 days ago

Hi @CloudLevi, thank you for reaching out. I was able to reproduce the issue. I'll notify our engineers about this and see what we do here. Thanks!

daymxn commented 6 days ago

This is a known issue when using protobuf-java and protobuf-javalite at the same time. See protobuf/issues/8104 for context.

You'll need to exclude either javalite or protobuf-java.

CloudLevi commented 5 days ago

@daymxn thank you for your response. The thing is, I've tried many combinations of excluding modules and still can't get a successful build. I'll list some examples of what I've tried.

Excluding protobuf-javalite

Code:

configurations {
    implementation.exclude module:'protobuf-javalite'
}

Result: Build fails, seems to be caused by a conflict between com.google.api.grpc:proto-google-common-protos and com.google.firebase:protolite-well-known-types (see file: exclude_javalite_only.txt)

Excluding protobuf-javalite and protolite-well-known-types

Code:

configurations {
    implementation.exclude module:'protobuf-javalite'
    implementation.exclude module:'protolite-well-known-types'
}

Result: Build succeeds, but app immediately crashes due to firestore failing to initialize. (see file: exclude_javalite_and_well_known_types.txt)

Excluding protobuf-javalite and proto-google-common-protos

Code:

configurations {
    implementation.exclude module:'protobuf-javalite'
    implementation.exclude module:'proto-google-common-protos'
}

Result: Build fails due to conflicts between protobuf-java and com.google.firebase:protolite-well-known-types. (see file: exclude_javalite_and_google_common_protos.txt)

Excluding protobuf-java

Code:

configurations {
    implementation.exclude module:'protobuf-java'
}

Result: build fails due to missing classes for pubsub (these are the ones I used in the project, I'm sure there are others):

class file for com.google.protobuf.MessageOrBuilder not found
class file for com.google.protobuf.GeneratedMessageV3 not found

I understand that most likely the answer lies in one of these configurations, but for now I couldn't find a combination with which the app will build and there will be no runtime errors. Any help would be appreciated, thank you.