skip to Main Content

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…

2

Answers


    1. Project level gradle file is fine.

    2. build.gradle(app)
      a)Inside of plugin block-> paste

      id("com.google.gms.google-services")

    b)Inside of dependencies block ->paste

    implementation("com.google.firebase:firebase-analytics")
    implementation(platform("com.google.firebase:firebase-bom:33.3.0"))
    

    just use these two dependencies , auth dependency you can directly import in your activity file.

    As for code , I am Providing you a code block from my sample test app

    val currentUser = auth.currentUser
    val userId = currentUser?.uid
    try {
                    val userId = auth.currentUser?.uid
                    //val currentTotal = total.text.toString().toIntOrNull() ?: 0
                    val addedAmount = amount.text.toString().toInt()
    
                    // Update total and save to SharedPrefs
                    val newTotal = total.text.toString().toInt() + addedAmount
                    total.text = newTotal.toString()
                    SharedPrefs.getInstance(context = this).save("Amount", newTotal.toString())
                    val expense = hashMapOf(
                        "description" to desc.text.toString(),
                        "amount" to amount.text.toString().toInt(),
                        "timestamp" to System.currentTimeMillis(),
                        "total" to newTotal,
                        "date" to TxtDate.text.toString()
                    )
                    userId?.let {
                        FirebaseFirestore.getInstance().collection("users").document(it)
                            .collection("expenses")
                            .add(expense)
                            .addOnSuccessListener {
                                clearEditTexts()
                                MessageUtilDialog.errorMessagedialog(this,"Expense Added")
                            }.addOnFailureListener {
                                MessageUtilDialog.errorMessagedialog(this,"Expense Not Added")
                            }
    
                            }
                } catch (e: NumberFormatException) {
                    // Handle invalid number input
                    MessageUtilDialog.errorMessagedialog(this, "Invalid number format")
                    //Toast.makeText(this, "Invalid number format", Toast.LENGTH_SHORT).show()
                }
            }
    

    Check this code and try to make the connection (Firebase.Firestore.getInstance().collection("your firestore db name")

    Login or Signup to reply.
  1. The issue you’re encountering seems to be related to the io.grpc library, which is often used by Firebase Firestore for its networking layer. This could be a result of version mismatches between the libraries you’re using. Also, since FirebaseAuth works fine, it’s likely a version conflict rather than a network issue. You could try updating to the latest version to ensure compatibility between Firebase components.

    If updating and managing the dependencies doesn’t resolve the problem, try testing Firestore operations on a separate project or environment to rule out other causes.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search