FirebaseInstanceId 令牌检索失败 SERVICE_NOT_AVAILABLE

我正在开发一个 Android 应用程序,它使用 Firebase 验证、数据库和存储。在 logcat 中出现此错误消息之前,一切正常。(我没有篡改任何消防控制台的配置)

E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE

这个错误消息显示,即使我已经注释了所有与 Firebase 相关的代码。< br > < br > 因此我无法继续进行身份验证和其他与 firebase 相关的东西。
是的,我连上了互联网,而且还有了一个新的谷歌服务。Json 文件从 Firebase 控制台,但它没有任何区别。< br >

78230 次浏览

you need to update the emulator to the latest version that includes Google Play services

I changed my emulator and now it is working correctly without any error.

"Cold Boot Now" Device in AVD Manager worked for me.

Edit: After updating emulators and than doing the cold boot it helped. – parohy Apr 5 at 9:22

I also faced with this issue. As I can see it can happen for many reasons.

Finally I figured out that my problem was that the current latest Facebook Android SDK version (v4.36.0) has a bug. Everything works fine if I set it back to v4.35.0. Maybe this info can help someone in the future.

You can find here the releases: https://github.com/facebook/facebook-android-sdk/releases

Stop emulator device and open AVD Manager Panel, edit device configuration. In device configuration panel "Show Advanced Settings" in "Emulated Performance" section select "Cold boot" option as Boot Option then click Finish, it should be worked.

enter image description here

Root cause: You miss google services in your device. So if you use emulator then apply "Cold boot" mode in advanced setting, if you use real device please change another enter image description here

For future readers:

Found this error when I set device date different than current and open. My application logs start printing similar log. Solution: restart your device and it will start working fine.

Check that Google play services are enabled

if it still shows error Now try these steps

Step 1 - Stop emulator device

Step 2 - open AVD Manager Panel, edit device configuration. In device configuration panel "Show Advanced Settings" in "Emulated Performance" section select "Cold boot" option as Boot Option then click Finish, it should be worked.

If this does not work try to work on different Emulator

You could be using a deprecated version of Google Play Services on your device, try upgrading your Play Services first.

For me, this was a connection issue with my emulator. I was unable to load websites outside of my company's VPN. Probably worth confirming that you can do that (load up yahoo or stackoverflow on the device's browser) if you're having this issue. Once I figured out my emulator's connection issues, I was able to get the token.

In my case, I was facing an Internet connectivity Issue. Make sure your Internet Connection is Strong enough to Generate FcmToken.

Visual Studio 2022 menu:

  1. Tools
  2. Android
  3. Android Device Manager
  4. Select device and click Edit

enter image description here