E/FirebaseInstanceId:获取 FIS 身份验证令牌失败

Posted

技术标签:

【中文标题】E/FirebaseInstanceId:获取 FIS 身份验证令牌失败【英文标题】:E/FirebaseInstanceId: Failed to get FIS auth token 【发布时间】:2020-06-23 09:58:55 【问题描述】:

我已按照 firebase 创建项目的所有步骤进行操作。 当我运行我的应用程序时,我收到以下错误: java.util.concurrent.ExecutionException: com.google.firebase.installations.FirebaseInstallationsException

我在 build.gradle 中添加了必要的库

但它仍然给我错误。有什么解决办法吗?

完整的堆栈跟踪如下:

-11 17:31:28.460 8093-8093/com.myapp V/FA: Registered activity lifecycle callback
03-11 17:31:28.510 8093-8153/com.myapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
03-11 17:31:28.550 8093-8156/com.myapp I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
03-11 17:31:28.550 8093-8093/com.myapp I/FirebaseInitProvider: FirebaseApp initialization successful
03-11 17:31:28.550 8093-8156/com.myapp I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
03-11 17:31:28.570 8093-8158/com.myapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
03-11 17:31:28.590 8093-8158/com.myapp I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
03-11 17:31:28.690 8093-8093/com.myapp W/art: Before android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
03-11 17:31:28.700 8093-8093/com.myapp V/FA: onActivityCreated
03-11 17:31:28.720 8093-8139/com.myapp V/FA: App measurement collection enabled
03-11 17:31:28.720 8093-8139/com.myapp V/FA: App measurement enabled for app package, google app id: com.myapp, 1:694013098939:android:9c791b689fec2f9f78629e
03-11 17:31:28.720 8093-8139/com.myapp I/FA: App measurement initialized, version: 22048
03-11 17:31:28.720 8093-8139/com.myapp I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
03-11 17:31:28.720 8093-8139/com.myapp I/FA: To enable faster debug mode event logging run:
      adb shell setprop debug.firebase.analytics.app com.myapp
03-11 17:31:28.720 8093-8139/com.myapp D/FA: Debug-level message logging enabled
03-11 17:31:28.750 8093-8093/com.myapp I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
03-11 17:31:28.750 8093-8093/com.myapp I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
03-11 17:31:28.850 8093-8093/com.myapp D/TextView: setTypeface with style : 0
03-11 17:31:28.980 8093-8093/com.myapp D/TextView: setTypeface with style : 0
03-11 17:31:28.990 8093-8093/com.myapp I/Timeline: Timeline: Activity_launch_request id:com.myapp time:8027824
03-11 17:31:29.150 8093-8157/com.myapp E/FirebaseInstanceId: Failed to get FIS auth token
    java.util.concurrent.ExecutionException: com.google.firebase.installations.FirebaseInstallationsException
        at com.google.android.gms.tasks.Tasks.zzb(Unknown Source)
        at com.google.android.gms.tasks.Tasks.await(Unknown Source)
        at com.google.firebase.iid.zzs.zzb(com.google.firebase:firebase-iid@@20.1.1:54)
        at com.google.firebase.iid.zzs.zza(com.google.firebase:firebase-iid@@20.1.1:89)
        at com.google.firebase.iid.zzv.run(com.google.firebase:firebase-iid@@20.1.1)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
        at java.lang.Thread.run(Thread.java:818)
     Caused by: com.google.firebase.installations.FirebaseInstallationsException
        at com.google.firebase.installations.FirebaseInstallations.doRegistrationInternal(com.google.firebase:firebase-installations@@16.0.0:333)
        at com.google.firebase.installations.FirebaseInstallations.doGetId(com.google.firebase:firebase-installations@@16.0.0:280)
        at com.google.firebase.installations.FirebaseInstallations.access$lambda$0(com.google.firebase:firebase-installations@@16.0.0)
        at com.google.firebase.installations.FirebaseInstallations$$Lambda$1.run(com.google.firebase:firebase-installations@@16.0.0)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
        at java.lang.Thread.run(Thread.java:818) 

【问题讨论】:

这个答案 (***.com/a/61529757/1677234) 为我解决了问题 【参考方案1】:

云消息传递版本 20.1.1 更新日志:

使用 Firebase 自动初始化过程和 Gradle 插件将 google-services.json 转换为资源的应用不受影响。但是,创建自己的 FirebaseOptions 实例的应用必须提供有效的 API 密钥、Firebase 项目 ID 和应用 ID。

google said: be aware of the following

打开 Firebase 控制台。 如果有任何新的条款和条件,请接受。 检查包名不匹配。 如果一切看起来都很好, 再次为您的应用添加 Firebase 设置。

【讨论】:

【参考方案2】:

我的第一个工作应用使用了 com.google.firebase:firebase-messaging:20.2.0。然后我复制该项目以制作我的第二个应用程序。我在 firebase 控制台中注册了新应用并替换了 google-services.json。当我运行时,我得到了同样的错误。我通过降级到版本 20.1.5 解决了这个问题。之后我升级到 20.2.3 版本,通知仍然有效。

【讨论】:

【参考方案3】:

更新您的google-services.json 文件。删除旧的并从Firebase console &gt; Project Settings重新下载新的google-services.json

【讨论】:

【参考方案4】:

如果你的 json 没问题,运行干净的项目。

【讨论】:

谢谢,我在 firebase 控制台中添加了新的 debug.keystore SHA-1 密钥,并更新了 google-services.json,但忘记清理项目。现在可以了。【参考方案5】:

第 1 步:- 使用 FirebaseOption 更新您的代码

FirebaseOptions options = new FirebaseOptions.Builder()
                .setApplicationId(FIREBASE_APPLICATION_ID)
                .setProjectId(FIREBASE_PROJECT_ID)
                .setGcmSenderId(FIREBASE_GCM_SENDER_ID)
                .setApiKey(FIREBASE_APIKEY_ID)
                .build();

        FirebaseApp.initializeApp( getApplicationContext(), options);

第 2 步:-

/谷歌播放服务/

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

implementation 'com.google.android.gms:play-services-auth:19.0.0'
// Firebase and ML Kit dependencies
implementation 'com.google.firebase:firebase-core:18.0.3'
implementation 'com.google.android.gms:play-services-vision:20.1.3'
implementation 'com.google.firebase:firebase-ml-vision-barcode-model:16.1.2'

// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:27.1.0')

// 声明 Crashlytics 和 Analytics 库的依赖项

// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-ml-vision'

第 3 步:-

 <service
        android:name="com.google.firebase.components.ComponentDiscoveryService"
        android:directBootAware="true"

        android:exported="false">
        <meta-data
            android:name="com.google.firebase.components:com.google.firebase.messaging.FirebaseMessagingRegistrar"
            android:value="com.google.firebase.components.ComponentRegistrar" />
        <meta-data
            android:name="com.google.firebase.components:com.google.firebase.datatransport.TransportRegistrar"
            android:value="com.google.firebase.components.ComponentRegistrar" />
        <meta-data
            android:name="com.google.firebase.components:com.google.firebase.iid.Registrar"
            android:value="com.google.firebase.components.ComponentRegistrar" />
        <meta-data
            android:name="com.google.firebase.components:com.google.firebase.installations.FirebaseInstallationsRegistrar"
            android:value="com.google.firebase.components.ComponentRegistrar" />
        <!--
            This registrar is not defined in the dynamic-module-support sdk itself to allow non-firebase
            clients to use it as well, by defining this registrar in their own core/common library.
        -->
        <meta-data
            android:name="com.google.firebase.components:com.google.firebase.dynamicloading.DynamicLoadingRegistrar"
            android:value="com.google.firebase.components.ComponentRegistrar" />

    </service>

    <provider
        android:name="com.google.firebase.provider.FirebaseInitProvider"
        android:authorities="Your_package_name.firebaseinitprovider"
        android:directBootAware="true"
        android:exported="false"
        android:initOrder="100" />
   <receiver
        android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <category android:name="Your_package_name" />
        </intent-filter>
    </receiver>

步骤:- 4 包括权限

All you have to do is just make the API key you are using has permission to the following APIs:
Firebase Installations API
Firebase Cloud Messaging API
Cloud Messaging
FCM Registration API

You can change the restrictions from your google cloud -> APIs & Services -> Credentials.

这是我在代码中试用和使用的完整解决方案

【讨论】:

【参考方案6】:

似乎是 firebase SDK (com.google.firebase:firebase-analytics:17.2.3) 的问题。我仍然得到相同的日志

Fatal Exception: java.lang.IllegalStateException
com.google.firebase.iid.FirebaseInstanceId.zzl (com.google.firebase:firebase-iid@@20.1.1:75)
com.google.firebase.iid.FirebaseInstanceId.getId (com.google.firebase:firebase-iid@@20.1.1:49)
com.google.firebase.perf.internal.zzf.zzbu (com.google.firebase:firebase-perf@@19.0.5:181)
com.google.firebase.perf.internal.zzf.zzbt (com.google.firebase:firebase-perf@@19.0.5:44)

【讨论】:

以上是关于E/FirebaseInstanceId:获取 FIS 身份验证令牌失败的主要内容,如果未能解决你的问题,请参考以下文章

Android 应用程序在模拟器中启动时崩溃

APN 中的 Firebase 令牌生成器失败

urllib模块

如何获取带有“F”标志的 Facebook 个人资料图片?

LUA怎么获取指定的函数返回值

获取文件名称