firebase / firebase-android-sdk

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

duplicate class com.google.protobuf.DescriptorProtos #5997

Open dpredovic opened 4 months ago

dpredovic commented 4 months 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

protolite-well-known-types:18.0.0 contains "com.google.protobuf.DescriptorProtos", the same class as protobuf-javalite:4.27.0, resulting in the CheckDuplicatesRunnable failing:

Duplicate class com.google.protobuf.DescriptorProtos found in modules protobuf-javalite-4.27.0.jar -> protobuf-javalite-4.27.0 (com.google.protobuf:protobuf-javalite:4.27.0) and protolite-well-known-types-18.0.0.aar -> protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0)

Steps to reproduce:

try building an app with libraries above

What happened? How can we make the problem occur? This could be a description, log/console output, etc.

Relevant Code:

// TODO(you): code here to reproduce the problem
lehcar09 commented 4 months ago

Hi @dpredovic, thank you for reaching. Firebase uses protolite that includes the protolite-well-known-types module. To resolve the issue, you have to exclude the protolite-well-known-types module from the Firebase products.

app/build.gradle.kts

dependencies {
    implementation(platform("com.google.firebase:firebase-bom:33.0.0"))
    implementation("com.google.firebase:firebase-firestore") {
         exclude(group = "com.google.firebase", module = "protolite-well-known-types")
    }
    implementation("com.google.protobuf:protobuf-javalite:4.27.0")
}

That said, I’ll go ahead and close this issue. Let me know if there’s any misunderstanding and/or we need to re-open the issue for further investigation.

dpredovic commented 4 months ago

Excluding the library fixes the build error, but leads to missing class at runtime:

 java.lang.RuntimeException: Internal error in Cloud Firestore (25.0.0).
at com.google.firebase.firestore.util.AsyncQueue.lambda$panic$3(AsyncQueue.java:545)
at com.google.firebase.firestore.util.AsyncQueue$$ExternalSyntheticLambda3.run(D8$$SyntheticClass:0)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8177)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/type/LatLng;
at com.google.firestore.v1.Value.dynamicMethod(Value.java:1806)
at com.google.protobuf.GeneratedMessageLite.dynamicMethod(GeneratedMessageLite.java:290)
at com.google.protobuf.GeneratedMessageLite.buildMessageInfo(GeneratedMessageLite.java:360)
at com.google.protobuf.GeneratedMessageInfoFactory.messageInfoFor(GeneratedMessageInfoFactory.java:37)
at com.google.protobuf.ManifestSchemaFactory$CompositeMessageInfoFactory.messageInfoFor(ManifestSchemaFactory.java:126)
at com.google.protobuf.ManifestSchemaFactory.createSchema(ManifestSchemaFactory.java:33)
at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:68)
at com.google.protobuf.Protobuf.schemaFor(Protobuf.java:82)
at com.google.protobuf.GeneratedMessageLite.makeImmutable(GeneratedMessageLite.java:203)
at com.google.protobuf.GeneratedMessageLite$Builder.buildPartial(GeneratedMessageLite.java:484)
at com.google.protobuf.GeneratedMessageLite$Builder.build(GeneratedMessageLite.java:490)
at com.google.firebase.firestore.model.ObjectValue.<init>(ObjectValue.java:60)
at com.google.firebase.firestore.model.MutableDocument.newInvalidDocument(MutableDocument.java:94)
at com.google.firebase.firestore.local.SQLiteRemoteDocumentCache.getAll(SQLiteRemoteDocumentCache.java:128)
at com.google.firebase.firestore.local.SQLiteRemoteDocumentCache.get(SQLiteRemoteDocumentCache.java:116)
at com.google.firebase.firestore.local.LocalDocumentsView.getBaseDocument(LocalDocumentsView.java:413)
at com.google.firebase.firestore.local.LocalDocumentsView.getDocument(LocalDocumentsView.java:92)
at com.google.firebase.firestore.local.LocalDocumentsView.getDocumentsMatchingDocumentQuery(LocalDocumentsView.java:292)
at com.google.firebase.firestore.local.LocalDocumentsView.getDocumentsMatchingQuery(LocalDocumentsView.java:268)
at com.google.firebase.firestore.local.QueryEngine.executeFullCollectionScan(QueryEngine.java:307)
at com.google.firebase.firestore.local.QueryEngine.getDocumentsMatchingQuery(QueryEngine.java:112)
at com.google.firebase.firestore.local.LocalStore.executeQuery(LocalStore.java:866)
at com.google.firebase.firestore.core.SyncEngine.initializeViewAndComputeSnapshot(SyncEngine.java:223)
at com.google.firebase.firestore.core.SyncEngine.listen(SyncEngine.java:210)
at com.google.firebase.firestore.core.EventManager.addQueryListener(EventManager.java:142)
at com.google.firebase.firestore.core.FirestoreClient.lambda$listen$7$com-google-firebase-firestore-core-FirestoreClient(FirestoreClient.java:181)
at com.google.firebase.firestore.core.FirestoreClient$$ExternalSyntheticLambda15.run(D8$$SyntheticClass:0)
at com.google.firebase.firestore.util.AsyncQueue.lambda$enqueue$2(AsyncQueue.java:444)
at com.google.firebase.firestore.util.AsyncQueue$$ExternalSyntheticLambda4.call(D8$$SyntheticClass:0)
at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor.lambda$executeAndReportResult$1(AsyncQueue.java:330)
at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$$ExternalSyntheticLambda2.run(D8$$SyntheticClass:0)
lehcar09 commented 4 months ago

Apologies about that. Per checking, the issue occurs in version protobuf-javalite:4.27.0. Based on Maven Protocol Buffers [Lite] Repository, 4.27.0 seems to be in beta version.

I tried using the protobuf-javalite:4.26.1 and I did not encounter build and/ or runtime issues. Aside from that, even not excluding the protolite-well-known-types from Firebase Firestore dependency, build and/ or runtime issues.

Here’s my update dependencies: app/build.gradle.kts

    implementation(platform("com.google.firebase:firebase-bom:33.0.0"))
    implementation("com.google.firebase:firebase-messaging")
    implementation("com.google.firebase:firebase-firestore")

    implementation("com.google.protobuf:protobuf-javalite:4.26.1")

Could you check if that works with you as well?

dpredovic commented 4 months ago

The old protobuf version works, no problem. I already downgraded, but we need a better solution.

lehcar09 commented 4 months ago

Thank you for your confirmation. I'll notify our engineers about this issue and see what we can do here.

In the meantime, I suggest using the version protobuf-javalite: 4.26.1.

rlazo commented 4 months ago

Hi @dpredovic thanks for raising this issue.

TL;DR; The latest version of protobuf-javalite (4.27) is not compatible with Firebase SDKs. Depend on an older version (4.26.x) while we fix the issue.

Here's the rundown of the problem.

  1. Older versions of the protobuf-javalite library did not include the DescriptorProto class in them.
  2. We, Firebase, worked around the issue by providing it ourselves in the protolite-well-known-types sdk (https://github.com/firebase/firebase-android-sdk/blob/master/protolite-well-known-types/src/main/proto/google/protobuf/descriptor.proto)
  3. In the latest release of protobuf-javalite from May 23 upstream included this change (https://github.com/protocolbuffers/protobuf/commit/500c953d105d0447479be259a5fb0b6f7124e978#diff-7b118ca1a27fe212e2315ba1ab008be7de574c6eae4d52ace00e15869ea418a0) that adds that class to the library.
  4. This is causing the duplicated classes

We'll work on our end and release new versions of the affected SDKs that don't have this issue. In the meanwhile, the workaround is using an older version of protobuf-javalite.

I'll keep this issue open until the new versions are out.

Thanks again!

NoyaD9 commented 3 months ago

Any update on that one? I see the new protobuf 4.27.1 is there but the error seems to still be there

daymxn commented 3 months ago

Hi @dpredovic thanks for raising this issue.

TL;DR; The latest version of protobuf-javalite (4.27) is not compatible with Firebase SDKs. Depend on an older version (4.26.x) while we fix the issue.

Here's the rundown of the problem.

  1. Older versions of the protobuf-javalite library did not include the DescriptorProto class in them.
  2. We, Firebase, worked around the issue by providing it ourselves in the protolite-well-known-types sdk (https://github.com/firebase/firebase-android-sdk/blob/master/protolite-well-known-types/src/main/proto/google/protobuf/descriptor.proto)
  3. In the latest release of protobuf-javalite from May 23 upstream included this change (protocolbuffers/protobuf@500c953#diff-7b118ca1a27fe212e2315ba1ab008be7de574c6eae4d52ace00e15869ea418a0) that adds that class to the library.
  4. This is causing the duplicated classes

We'll work on our end and release new versions of the affected SDKs that don't have this issue. In the meanwhile, the workaround is using an older version of protobuf-javalite.

I'll keep this issue open until the new versions are out.

Thanks again!

We should be able to fix this issue by removing the "extra" types we provide, and updating our protobuf dependency to 4.27+. Unfortunately, the removal of the extra types we provide is not the only breaking change that occurs between 3.0 and 4.0. Currently, updating our protobuf dependency to 4.27+ causes a variety of breaking changes across our ecosystem; changes that would require moderate overhead investigating and fixing. This is definitely something we're interested in doing, but we do not currently have the free cycles to handle it.

In the meantime, we'll leave this bug open until we get around to fixing this, and also so that folks can give their +1.

ygnessin commented 1 month ago

Hi @daymxn, any update on this issue? I see that https://github.com/firebase/firebase-android-sdk/pull/5999 is approved but not yet merged.

Will a fix be included in the next release?

Thank you so much for your attention to this issue!

elevenfive commented 1 week ago

For anyone wondering it looks like the recent CVE from this week does not affect 4.26.x thankfully so folks can stay on that until this issue is fixed.

https://www.cve.org/CVERecord?id=CVE-2024-7254