[Bug Report] gRPC dependency conflict between firebase-firestore and generativeai SDK causes NoClassDefFoundError
[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.
- Create an Android project using Kotlin and Compose.
- Add dependencies for both the Firebase BOM (
34.6.0) and the Google Generative AI SDK (0.9.0). - Implement Firebase Google Authentication.
- After a successful sign-in, attempt to perform any Firestore operation (e.g.,
firestore.collection("users").document(uid).get()). - 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.
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
@inuyamoku-gif, thank you for the detailed report. I'm glad you posted your workaround, it may also help others.
According to the README for the repo, the generative AI SDK is deprecated and superseded by Firebase AI logic. Since Firebase AI logic is part of the Firebase SDK alongside Firestore, I suspect you will no longer experience this issue ifyou upgrade to Firebase AI logic.
Thank you for your quick response and the detailed explanation. I can confirm that the workaround using resolutionStrategy (forcing io.grpc versions to 1.57.2) has resolved the issue in my environment. I also understand that the generative AI SDK is deprecated and that migrating to Firebase AI Logic is the recommended permanent solution that should prevent this issue from recurring. I will proceed with the migration plan for my project. Regarding this Issue: Since a clear path forward (migration to Firebase AI Logic) has been identified, should I close this issue now, or should it remain open for the team to address the underlying dependency conflict in the deprecated SDK? Thank you again for your valuable feedback.