Repository navigation
Description
[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:
- For general technical questions, post a question on StackOverflow
with the firebase tag. - For general Firebase discussion, use the firebase-talk
google group. - For help troubleshooting your application that does not fall under one
of the above categories, reach out to the personalized
Firebase support channel.
[REQUIRED] Step 2: Describe your environment
- Android Studio version: 3.6.3
- Firebase Component: Firestore
- Component version: 22.0.0
[REQUIRED] Step 3: Describe the problem
Hello, I've faced a problem when I tried to add Firestore to my app.
My app has gRPC+protobuf(not lite) dependencies for client<->server interaction .
So, I have to exclude all possible sub dependencies of group: 'com.google.protobuf', module: 'protobuf-javalite to avoid duplicated classes.
But with firestore there is another problem, becaiuse it has group: 'com.google.firebase', module: 'protolite-well-known-types' within and from the other side grpc-protobuf has com.google.api.grpc:proto-google-common-protos.
I can exclude protolite-well-known-types from firestore dependency but it leads to runtime crash with such message:
jjava.lang.VerifyError: Verifier rejected class com.google.firestore.v1.Value: void com.google.firestore.v1.Value.mergeGeoPointValue(com.google.type.LatLng) failed to verify: void com.google.firestore.v1.Value.mergeGeoPointValue(com.google.type.LatLng): [0x19] register v4 has type Precise Reference: com.google.type.LatLng but expected Reference: com.google.protobuf.GeneratedMessageLite
void com.google.firestore.v1.Value.mergeTimestampValue(com.google.protobuf.Timestamp) failed to verify: void com.google.firestore.v1.Value.mergeTimestampValue(com.google.protobuf.Timestamp): [0x19] register v4 has type Precise Reference: com.google.protobuf.Timestamp but expected Reference: com.google.protobuf.GeneratedMessageLite (declaration of 'com.google.firestore.v1.Value' appears in /data/app/com.example.app-zClj9DiMiOtZXvrAL6Wf3A==/base.apk!classes2.dex)
Otherwise, if I exclude com.google.api.grpc:proto-google-common-protos, i still receive messages about duplicate classes (f.e. com.google.protobuf.DescriptorProtos)
Can someone suggest any solution to avoid such collision?
deps.txt
Steps to reproduce:
I have attached output for dependencies task
Relevant Code:
implementation (libraryDependencies.firebaseFirestore) {
exclude group: 'com.google.protobuf', module: 'protobuf-javalite' //kek
exclude group: 'com.google.firebase', module: 'protolite-well-known-types' //kek
}
Activity
var-const commentedon Nov 11, 2020
Hi and sorry you're experiencing issues. Unfortunately, Firestore doesn't support mixing Protobuf and Protobuf-lite. Note that
excludewon't help in this case because both the dependencies are actively used by the corresponding library. Are you using any other APIs in your app (except for gRPC, which can use Protobuf-lite) that rely on Protobuf?If you're using other APIs, one potential workaround might be to call them via a Firebase Function (you could call Firestore via a Function as well, but that would eliminate the real-time benefits). Another option might be to fork the Firestore repo and see if you can make it work if you switch the dependency on Protobuf-lite with regular Protobuf.
(note: this is similar to #607)
dmytroreutov commentedon Nov 11, 2020
Hi @var-const. Thank you for your reply. Seems like I should either migrate anything to protobuf-lite or fork Firestore repo. I'll try one of them or both and reach out with results. One question, do your team ever consider about to get rid of strict protobuf-lite dependency? I remember +- same issues with https://github.com/google/tink which is used as a dependency for androidx:crypto. As I know, they removed lite dependency.
wilhuff commentedon Nov 11, 2020
Firestore stores data in its offline storage in protobuf format so we can't just e.g. switch to JSON without losing writes that are in progress.
dmytroreutov commentedon Nov 11, 2020
What I'm trying to say that Firestore can use protobuf well known types like
com.google.protobuf.Timestamporcom.google.protobuf.LatLngbut not depend on particular implementation (com.google.protobuf.GeneratedMessageLiteorcom.google.protobuf.GeneratedMessageV3). I don't know is it a big problem, but such solution can help to simplify client usage of Firestorewilhuff commentedon Nov 11, 2020
Firestore doesn't directly depend on these things. Protobuf messages depend on each other in implementation specific ways, so when we depend on a Firestore
Valuemessage, that message depends onTimestamp. The verifier error you're seeing is that the protobuf-lite implementation ofValueis incompatible with the full implementation ofTimestamp.dmytroreutov commentedon Nov 11, 2020
That's was I meant to say. Firestore uses
protobuf-lite implementation ofValue``. And when I checked the code, I saw thatTimestamp, LatLng, etc. types are serialised and deserialised using `com.google.protobuf.GeneratedMessageLite`. So I'm trying to figure out if it possible to have full protobuf implemetation of `Value` or have an abstraction which delegates processing of well-known types either as `GeneratedMessageV3` messages or `GeneratedMessageLite`wilhuff commentedon Nov 11, 2020
I doubt Firestore is sensitive to which implementation of the messages it actually uses; you just can't mix and match message implementations for dependent messages.
Any abstraction that would allow these things to mix would have to be added to the generated message code, which is a significant undertaking.
Meanwhile, note that this path you're going down only really addresses the first order problem of incompatibility of between a protobuf-javalite
Valueand a protobufTimestamp. Once you resolve it there will be other problems because the message classes built into the firebase-firestore AAR depend on protobuf-javalite in other ways.You have essentially three options:
Note that protobuf-javalite is specifically designed for Android and that after proguarding the resulting binary is much smaller that the full runtime. If you have the choice I'd advise taking the first path and migrating to protobuf-javalite for Android.
I'm going to close this issue because there really isn't anything we can do about this. Multiple Java protobuf implementations are an unfortunate fact of life in this ecosystem and we have to pick one to ship a self-contained library.