Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the firestore isn't working on android studio

I try to implement firestore on my android project. I have follow everything on the official firebase wesbite. I am getting those errors :

2020-11-03 19:38:47.569 8695-8760/com.example.alllerrr E/AndroidRuntime: FATAL EXCEPTION: grpc-okhttp-0
Process: com.example.alllerrr, PID: 8695
java.lang.AssertionError: Method getAlpnSelectedProtocol not supported for object SSL socket over Socket[address=firestore.googleapis.com/172.217.19.234,port=443,localPort=46122]
    at io.grpc.okhttp.internal.OptionalMethod.invoke(OptionalMethod.java:114)
    at io.grpc.okhttp.internal.OptionalMethod.invokeWithoutCheckedException(OptionalMethod.java:135)
    at io.grpc.okhttp.OkHttpProtocolNegotiator$AndroidNegotiator.getSelectedProtocol(OkHttpProtocolNegotiator.java:183)
    at io.grpc.okhttp.OkHttpProtocolNegotiator$AndroidNegotiator.negotiate(OkHttpProtocolNegotiator.java:145)
    at io.grpc.okhttp.OkHttpTlsUpgrader.upgrade(OkHttpTlsUpgrader.java:63)
    at io.grpc.okhttp.OkHttpClientTransport$4.run(OkHttpClientTransport.java:571)
    at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:923)

I have implemented okhttp and put

<uses-permission android:name="android.permission.INTERNET"/>

on the manifest file. But nothing is working: the app is still crashing. Here is my code:

val userID = auth.currentUser
                db.collection("users").document(userID.toString())
                val Map = hashMapOf<String, Any>()
                Map["pseudo"] = name.toString()
                db.collection("users")
                        .add(Map)
                        .addOnSuccessListener { documentReference ->
                            Toast.makeText(baseContext, "succes:" + userID,
                                    Toast.LENGTH_SHORT).show()
                        }
                        .addOnFailureListener { e ->
                            Toast.makeText(baseContext, "Veuillez essayer plus tard.",
                                    Toast.LENGTH_SHORT).show()
                        }

(I have tried tu put String instead of the "Any" in the hashmap variable.) If anyone have a clue!

like image 624
Malopieds Avatar asked Nov 03 '20 18:11

Malopieds


3 Answers

I experienced the same thing on android 11 and got around it by adding the following to my build.gradle file

implementation "io.grpc:grpc-okhttp:1.32.2"

like image 143
Joseph Geoffery Avatar answered Oct 12 '22 07:10

Joseph Geoffery


as the below answer add in android/app/build.gradle in dependencies section

dependencies {
    ....
    .....
    implementation "io.grpc:grpc-okhttp:1.32.2"
}
like image 20
ALEXANDER LOZANO Avatar answered Oct 12 '22 09:10

ALEXANDER LOZANO


I did try a solution from Joseph Geoffery

  • Open build.gradle file in your app folder
  • Add this in dependencies section
    implementation "io.grpc:grpc-okhttp:1.32.2"
    

this work for me

like image 1
Jacob Handaya Avatar answered Oct 12 '22 07:10

Jacob Handaya