invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.6k stars 2.19k forks source link

Cannot retrieve FCM token Error: SERVICE_NOT_AVAILABLE #2285

Closed patrikmasiar closed 5 years ago

patrikmasiar commented 5 years ago

Issue

Hi, I am using react-native-firebase for android push notifications. I have an issue with retrieving FCM token.

When I am logging error, it shows me: Error: SERVICE_NOT_AVAILABLE

Snímka obrazovky 2019-06-24 o 19 04 26

react-native-firebase: 5.2.0

android/build.gradle:

classpath 'com.android.tools.build:gradle:3.1.4'

android/app/build.gradle:

implementation project(':react-native-firebase')
implementation "com.google.android.gms:play-services-base:16.0.1"
implementation "com.google.firebase:firebase-core:16.0.6"
implementation "com.google.firebase:firebase-messaging:17.3.4"

react-native info output:

React Native Environment Info: System: OS: macOS 10.14.4 Binaries: Node: 11.5.0 npm: 6.9.0 Watchman: 4.9.0 SDKs: Android SDK: API Levels: 25, 27, 28, 29 Build Tools: 27.0.3, 28.0.3, 29.0.0 System Images: android-26 | Google APIs Intel x86 Atom npmPackages: react: ^16.6.3 => 16.6.3 react-native: ^0.57.8 => 0.57.8 npmGlobalPackages: react-native-cli: 2.0.1 react-native-git-upgrade: 0.2.7

mikehardy commented 5 years ago

It isn’t documented very well, but I believe this is either a network connectivity failure or a server error of some sort. Recommendation is exponential backoff/retry. The token calls have latency anyway, so your calling code should already be able to handle it async, it just may take longer (or fail completely if there’s a network hiccup)

https://stackoverflow.com/questions/50208426/android-fcm-java-io-ioexception-service-not-available-error-on-some-devices

provisionally closing as all the docs I read indicated this was network related, and not a problem with the module, additionally I’ve been running e2e tests this morning on the module, they call getToken and have been working so I can’t reproduce

shubham1164 commented 5 years ago

I am also facing this issue only after I enable progaurd along with migration to androidx, please suggest something

mikehardy commented 5 years ago

@shubham1164 can you confirm you have done this? https://rnfirebase.io/docs/v5.x.x/installation/android#Using-with-Proguard-enabled

And if it is just related to AndroidX you might be seeing a difference between R8 (new minify toolchain on Android) and ProGuard. You can disable R8 (I think, until they remove the option) https://android-developers.googleblog.com/2018/04/android-studio-switching-to-d8-dexer.html

shubham1164 commented 5 years ago

Yes, I have used all these but still no success until I added an additional config in the proguard:

-keep class com.google.firebase.* { ; }

It's working now. I don't know if it is fine to include the above line. Thanks

mikehardy commented 5 years ago

I don't think that will hurt you other than potentially keeping around a lot of classes that it may correctly delete, but that is better than incorrectly purging a class you need

That said, I notice your versions are old, I wonder if you upgraded to new versions of gradle + gradle plugin, and the version of firebase/play services right before they went androidx, along with react-native-firebase v5.5.x if you would still see this problem even without the proguard addition. I have updated versions and don't see this myself

shubham1164 commented 5 years ago

Thank you @mikehardy I will surely try that

hapSa000 commented 4 years ago

I have same problem ..... i want to do Push notification by firebase in android and i am doing coding from https://rnfirebase.io/docs/v5.x.x/installation/android#Using-with-Proguard-enabled ...... and i am getting error ;- Possible Uhandeled Promis Rejection ( id:1) Error: SERVICE_NOT_AVILABLE .... please help its urgent

srichallamalla935 commented 4 years ago

I am also getting same error Error: SERVICE_NOT_AVAILABLE in android. Please give any suggestions.I tried this -keep class com.google.firebase.** { *; } but no luck for me.

vgvishal538 commented 4 years ago

did anyone found any solution?

Sbphillips19 commented 4 years ago

Any updates on this. Facing same thing with android

Sander-Li commented 4 years ago

Any updates on this. Facing same thing with android

Flouwrian commented 4 years ago

Any updates on this. Facing same thing with android. I also get this error message:

messaging/fcm-token-error authentication failed

GabrielDierks commented 4 years ago

For me the issue was the internet connection of my macbook. Changing the network did the trick.

Yandamuri commented 3 years ago

This is absolutely network issue. If you are running in android emulator, kindly check wifi and mobile data aswll. sometimes for no emulator network connection is terminated. Then just close and open the emulator.

SimajjiHans commented 3 years ago

If you are running in Android emulator, try this answer from SO https://stackoverflow.com/questions/4376553/upgraded-to-sdk-2-3-now-no-emulators-have-connectivity

Or change your DNS to 8.8.8.8 and restart your emulator

syslogic commented 3 years ago

In case you may experience this on a HUAWEI device, it might just hint for that Google Play Services are not installed (and so there won't be any "Background Data Access"). When I run the very same application on a Motorola device or an x86 emulator, it doesn't complain at all ...particularly with Harmony OS 2.0 (I'm talking of 2021), there doesn't seem to be any way to properly install Google Play Services, because they refuse to OEM unlock (it's probably no wonder that their "AppGallery" has little variety, but still lots of rubbish). Firebase Authentication still works... but nothing that would require the "Background Data Access".

mikehardy commented 3 years ago

For non-Google Play devices, this page is important to understand: https://firebase.google.com/docs/android/android-play-services - also, you might like https://rnfirebase.io/app/utils#android---checking-play-services

syslogic commented 3 years ago

This is good news for me, because I barely use the libraries which would demand these (except the Google Play BillingClient, which is not applicable in the HUAWEI "AppGallery" anyway)... you've probably just sold a tablet for them, which I've already RMA'd and may cancel (still got one week left for testing some of the scenarios). By building two flavors, I can even keep these libraries out of the package - or substitute accordingly.

devthejo commented 3 months ago

solved by https://stackoverflow.com/a/68482204/5338073