简体   繁体   English

为什么 Firestore 在 android studio 上不起作用

[英]Why the firestore isn't working on android studio

I try to implement firestore on my android project.我尝试在我的 android 项目上实现 firestore。 I have follow everything on the official firebase wesbite.我已经关注了官方 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我已经实现了 okhttp 并把

<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! (我试过在 hashmap 变量中放置 String 而不是“Any”。)如果有人有线索!

我在 android 11 上遇到了同样的事情,并通过将以下内容添加到我的build.gradle文件中来解决它

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

as the below answer add in android/app/build.gradle in dependencies section作为下面的答案在依赖项部分添加 android/app/build.gradle

dependencies {
    ....
    .....
    implementation "io.grpc:grpc-okhttp:1.32.2"
}

I did try a solution from Joseph Geoffery我确实尝试过 Joseph Geoffery 的解决方案

  • Open build.gradle file in your app folder在您的应用程序文件夹中打开build.gradle文件
  • Add this in dependencies section在依赖项部分添加这个
    implementation "io.grpc:grpc-okhttp:1.32.2"

this work for me这对我有用

I got same mistake while moving Android 11 to Android 12 and adding我在将 Android 11 移动到 Android 12 并添加时遇到了同样的错误

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

to build.gradle(:app) is real solution... Thank you much... to build.gradle(:app) 是真正的解决方案......非常感谢......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM