firebase / firebase-android-sdk

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

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

Closed CloudLevi closed 3 weeks ago

CloudLevi commented 1 month 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 1 month 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 1 month 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 1 month 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.

davidmotson commented 4 weeks ago

I was able to reproduce this, however, in doing so I ran into something. I don't think com.google.cloud:google-cloud-pubsub is meant for use on Android. I think its meant for a server environment. Can you verify that it is usable in Android?

CloudLevi commented 3 weeks ago

@davidmotson you might be right... It's quite difficult to find valid information on this topic, but here's what I found.

Even though it seems like using pubsub on Android is possible, it's likely not the best approach. It would be better to connect it to Android via Firebase Messaging, as suggested here: https://stackoverflow.com/questions/75983750/pub-sub-on-android-via-google-sign-in

Also, I found this in connection to Firebase and PubSub: https://firebase.google.com/docs/functions/pubsub-events?gen=2nd

Here are some examples of pubsub usage on Android: https://github.com/hofstede-matheus/PubSubAndroidExample https://github.com/androidthings/weatherstation

I will investigate this approach and can report back, but it seems for now this particular issue of conflicts can be closed