Skip to content

[Bug Report] gRPC dependency conflict between firebase-firestore and generativeai SDK causes NoClassDefFoundError #7587

@inuyamoku-gif

Description

@inuyamoku-gif

[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: Android Studio Narwhal | 2024.1.1
  • Firebase Component: Auth, Firestore
  • Component version: 34.6.0

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

When using both the Firebase SDK (specifically Cloud Firestore) and the Google Generative AI SDK in the same Android project, a fatal runtime crash occurs. The crash is caused by a java.lang.NoClassDefFoundError for io.grpc.InternalGlobalInterceptors, which indicates a dependency version conflict between the io.grpc:* libraries used by the two SDKs.

This issue can manifest in subtle ways before the crash, such as FirebaseAuth.getInstance().currentUser being unexpectedly null after a successful sign-in. This suggests that the underlying gRPC conflict can also interfere with FirebaseAuth's ability to maintain its session state.

  1. Create an Android project using Kotlin and Compose.
  2. Add dependencies for both the Firebase BOM (34.6.0) and the Google Generative AI SDK (0.9.0).
  3. Implement Firebase Google Authentication.
  4. After a successful sign-in, attempt to perform any Firestore operation (e.g., firestore.collection("users").document(uid).get()).
  5. The app will crash with a NoClassDefFoundError.

Relevant Code:

The application crashes with the following fatal exception:
java.lang.RuntimeException: Internal error in Cloud Firestore (26.0.2). ... Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lio/grpc/InternalGlobalInterceptors; at io.grpc.internal.ManagedChannelImplBuilder.getEffectiveInterceptors(ManagedChannelImplBuilder.java:684) at io.grpc.internal.ManagedChannelImplBuilder.build(ManagedChannelImplBuilder.java:672) at io.grpc.ForwardingChannelBuilder2.build(ForwardingChannelBuilder2.java:278) at io.grpc.android.AndroidChannelBuilder.build(AndroidChannelBuilder.java:169) at com.google.firebase.firestore.remote.GrpcCallProvider.initChannel(GrpcCallProvider.java:116) ... 12 more

KotlinThe issue was fully resolved by forcing a consistent version for all transitive `io.grpc` dependencies in the `app/build.gradle.kts` file:kotlin // In app/build.gradle.kts configurations.all { resolutionStrategy { // Forcing gRPC versions to a compatible set (1.57.2) resolves the runtime crash. force("io.grpc:grpc-okhttp:1.57.2") force("io.grpc:grpc-stub:1.57.2") force("io.grpc:grpc-protobuf-lite:1.57.2") force("io.grpc:grpc-android:1.57.2") force("io.grpc:grpc-api:1.57.2") } }Kotlin---

Request to the Firebase Team

Please investigate the dependency mapping for firebase-firestore and its transitive gRPC dependencies. Ideally, the Firebase SDKs should be compatible with other major Google SDKs like the Generative AI SDK (com.google.ai.client.generativeai:generativeai:0.9.0) without requiring developers to manually implement a resolutionStrategy.force block. Aligning the gRPC versions would greatly improve the developer experience and prevent these hard-to-diagnose runtime crashes.

Thank you for your hard work and dedication to the Firebase platform.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions