gpt4 book ai didi

android - java.io.IOException : AUTHENTICATION_FAILED in Android Firebase (and SERVICE_NOT_AVAILABLE)

转载 作者:行者123 更新时间:2023-12-03 14:42:16 38 4
gpt4 key购买 nike

获取 firebase token 时,我在某些设备上遇到以下错误:

Fatal Exception: d.b.a.b.g.f
java.io.IOException: AUTHENTICATION_FAILED
com.google.android.gms.tasks.zzu.getResult (zzu.java:15)
MainActivity$3.onComplete (MainActivity.java:387)

Caused by java.io.IOException
AUTHENTICATION_FAILED
com.google.firebase.iid.zzu.then (zzu.java:16)
com.google.android.gms.tasks.zzd.run (zzd.java:5)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
com.google.android.gms.common.util.concurrent.zza.run (zza.java:6)
java.lang.Thread.run (Thread.java:784)
来自开发者控制台的错误日志:
com.google.android.gms.tasks.RuntimeExecutionException: 
at com.google.android.gms.tasks.zzu.getResult (zzu.java:15)
at com.example.MainActivity$3.onComplete (MainActivity.java:387)
at com.google.android.gms.tasks.zzj.run (zzj.java:4)
at android.os.Handler.handleCallback (Handler.java:808)
at android.os.Handler.dispatchMessage (Handler.java:101)
at android.os.Looper.loop (Looper.java:166)
at android.app.ActivityThread.main (ActivityThread.java:7529)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:921)
Caused by: java.io.IOException:
at com.google.firebase.iid.zzu.then (zzu.java:16)
at com.google.android.gms.tasks.zzd.run (zzd.java:5)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
at com.google.android.gms.common.util.concurrent.zza.run (zza.java:6)
at java.lang.Thread.run (Thread.java:784)
这是负责获取 firebase token 的代码:
FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (task.getResult() != null && task.isSuccessful()) {
String firebaseToken = task.getResult().getToken();
}
}
});
我正在使用以下 gradle 依赖项。
implementation 'com.google.firebase:firebase-analytics:17.4.3'
implementation 'com.google.firebase:firebase-crashlytics:17.0.1'
implementation 'com.google.firebase:firebase-messaging:20.2.0'
我发现了类似的 questions and problems但没有确凿的答案。有人认为这可能是互联网连接中断的结果,但我的应用程序需要在进入应用程序之前进行身份验证,以便互联网可用。有没有人遇到同样的问题?此致。
enter image description here

最佳答案

implementation platform('com.google.firebase:firebase-bom:26.4.0')
implementation "com.google.firebase:firebase-messaging"
炸弹已被埋下 (c) 谷歌……它还在那里……
最终得到以下代码:
    try {
FirebaseMessaging.getInstance().getToken().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
final String token = task.getResult();
//GOT the token!
}
});
} catch (Exception e) {
// OMG, Firebase is used to log Firebase crash :)
// I'm not sure if this will work...
FirebaseCrashlytics.getInstance().recordException(e);
gotFBCrash = true;
}
if (gotFBCrash) {
FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
final String token = task.getResult().getToken();
//GOT the token!
}
});
}
实际上,第二部分是两次弃用的代码(这就是我在这里的原因 - 更新到实际代码会导致应用程序崩溃)但它可以工作。如果您愿意并且讨厌 try/catch,则只能使用第二种方式获取 FCM token

关于android - java.io.IOException : AUTHENTICATION_FAILED in Android Firebase (and SERVICE_NOT_AVAILABLE),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62562243/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com