I'm trying to connect to firebase, but the app just keeps crashing. I understand I must be having some misaligned dependencies, but I believe I took the right versions according to: https://firebase.google.com/support/release-notes/android
The Build.gradle.kts contain:
plugins {
id("com.android.application") version "8.6.0"
id("org.jetbrains.kotlin.android") version "1.9.25"
id("com.google.gms.google-services") version "4.4.2"
}
dependencies {
// Firebase dependencies
implementation(platform("com.google.firebase:firebase-bom:33.3.0"))
implementation("com.google.firebase:firebase-auth:23.0.0")
implementation("com.google.firebase:firebase-firestore:25.1.0")
}
As for the project level:
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
id("com.google.gms.google-services") version "4.4.2" apply false
}
The code I'm using is the following, as as proof of concept..:
fun checkWhitelistByEmail(
email: String,
onAccessGranted: () -> Unit,
onAccessDenied: () -> Unit,
scope: CoroutineScope // Pass the coroutine scope from outside
) {
val db = Firebase.firestore
// val db = FirebaseFirestore.getInstance()
Log.d("FirestoreCheck", "Firestore instance initialized")
db.collection("whitelisted_users")
.get()
.addOnSuccessListener { result ->
for (document in result) {
Log.d("FirestoreCheck", "${document.id} => ${document.data}")
}
}
.addOnFailureListener { exception ->
Log.w("FirestoreCheck", "Error getting documents.", exception)
}
}
But it keeps crashing with:
FATAL EXCEPTION: main (Ask Gemini)
Process: com.flashc_ai.FlahsC_AI, PID: 5439
java.lang.RuntimeException: Internal error in Cloud Firestore (25.1.0).
at com.google.firebase.firestore.util.AsyncQueue.lambda$panic$3(AsyncQueue.java:546)
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: com.google.android.gms.tasks.RuntimeExecutionException: java.lang.RuntimeException: java.lang.NoClassDefFoundError: Failed resolution of: Lio/grpc/InternalGlobalInterceptors;
at com.google.android.gms.tasks.zzw.getResult(com.google.android.gms:play-services-tasks@@18.1.0:3)
at com.google.firebase.firestore.remote.FirestoreChannel.lambda$runBidiStreamingRpc$0$com-google-firebase-firestore-remote-FirestoreChannel(FirestoreChannel.java:146)
etc....
Any idea how I can arrange that, I'm really stuck with this bug since days and nothing works no matter what I try. Note, firebaseAuth works fine, so the connection setting is OK. Thanks!
I tried specifying the versions of the modules imported, tried to simplify the code to make a proof of concept...
thanks for the answers! In the end, I found the winning constellation, and don't dare to touch it anymore for now :D
build.gradle(app):
plugins {
id("com.android.application") version "8.6.0"
id("org.jetbrains.kotlin.android") version "1.9.25"
id("com.google.gms.google-services") version "4.4.2"
}
dependencies {
// Firebase dependencies
implementation(platform("com.google.firebase:firebase-bom:33.3.0"))
implementation("com.google.firebase:firebase-auth")
implementation("com.google.firebase:firebase-firestore")
implementation("io.grpc:grpc-okhttp:1.68.0")
implementation("io.grpc:grpc-protobuf-lite:1.68.0")
implementation("io.grpc:grpc-stub:1.68.0")
}
build.gradle(project):
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.jetbrains.kotlin.android) apply false
id("com.google.gms.google-services") version "4.4.2" apply false
}
Function:
fun checkEmail(
doctype: String,
onDocFound: () -> Unit,
onDocNotFound: () -> Unit
) {
val db = Firebase.firestore
db.collection("my_collection")
.document(doctype)
.get()
.addOnSuccessListener { document ->
if (document != null && document.exists()) {
// Document exists
onDocFound()
} else {
// Document doesn't exist
onDocNotFound()
}
}
.addOnFailureListener { e ->
Log.d("FirestoreCheck", "error: $e")
// Handle any errors
}
}