45

After reading 100's of threads and googling I am still confused about this following error message.

Currently, I am using Firebase Cloud Messaging and in very short terms I am trying to get my token from Firebase to be able to send messages to my server. I've tried with both these methods:

String token = FirebaseInstanceId.getInstance().getToken(mySenderId, "FCM");

String token = FirebaseInstanceId.getInstance().getToken();

So in the logs, I read this:

E/FirebaseInstanceId: Token retrieval failed: TOO_MANY_REGISTRATIONS
                                 java.io.IOException: TOO_MANY_REGISTRATIONS

According to other posts and answers, it's a cause of "Too many installed applications on the device that are registered with C2DM/GCM/FCM". I've also read there was a limitation of "Max 100 GCM/FCM registered applications installed on the device".

But this is not simply true, is it? I mean, it may be true but it isn't the whole answer to this issue. I am constantly working and testing with different devices and my current device DOES NOT have 100 applications registered with FCM. In fact, my device does not even have 100 applications installed at all, far from it!

Is there any way to manage previous registered devices and tokens? I've tried to run the following code without any luck:

FirebaseInstanceId.getInstance().deleteInstanceId();

I've tried to nail down information from different sources (including the documentation) without luck of understanding how this actually works. I've had the same issue with old the C2DM a while ago and also with GCM lately. I've merged with Firebase a few days ago to use its features instead which the thoughts of improvements on this, but it still echoes back at me.

AL.
  • 36,815
  • 10
  • 142
  • 281
Fatmajk
  • 1,770
  • 1
  • 13
  • 22
  • 2
    Have you tried running on different devices or an emulator to see if all produce the same error? – Bob Snyder Nov 28 '17 at 18:10
  • I have been trying on different devices yes. I've had the issue on basically 2 of 4 devices I've tested on. Currently I am testing on a Nexus 6P and it works fine for the moment, no error when receiving the token. With for example Huawei P10 the error consists. Haven't tried with an emulator no. Worth adding is that it was working with my Huawei P10 before. – Fatmajk Nov 29 '17 at 10:20
  • 1
    When I read your error, two problems came to mind. 1)The `senderId` is linked with more than 1 token. 2)(which is impossible I guess) is that the same token is linked with multiple `senderIds`. So could you please ensure that none of the above is true? And if you could post the code of how you're registering the client to firebase? – riadrifai Dec 05 '17 at 19:52
  • Can you explain a bit more what you mean please? What do you mean that the senderId is linked to more than 1 token? The token is generated by Firebase no? So the only thing I am providing in the getToken(...) method is the senderId itself along with "FCM". But anyway the getToken() method doesn't specify anything and is also suppose to be use for token generation. If I login into Firebase console there is only 1 senderId to use. – Fatmajk Dec 07 '17 at 13:34
  • I am seeing same errors in Firebase Crashlytics. Did you ever fix the issue? If yes then how? If no then, were you getting the errors all the time and you were ignoring them. – Rohit Singh Nov 30 '21 at 14:52

4 Answers4

54

After spoken directly with the Google team I got the following answer from them:

The team confirmed and clarified their data indicated that the device is not really a normal device and this is either:

  1. a virtual device (emulator) being reused too many times

  2. a real device used in automated way to test too many apps

  3. a real device which has been customized with a CLONE image of the system partition, CLONED from a different device

If this is a real device, the best way to solve it is to factory reset to the real system image of the device. Since this device is prob currently stuck in 2 or 3, would you mind factory resetting the device and let us know if the issue still reproduce?

I have performed a factory reset on my device and the issue is gone. I still don't see exactly how this can appear and why.

Fatmajk
  • 1,770
  • 1
  • 13
  • 22
  • 2
    I encountered the TOO_MANY_REGISTRATIONS error today while testing with a [Firebase Test Lab device](https://firebase.google.com/docs/test-lab/overview#choose-yourdevice-type). This appears to be explained by case 2: _a real device used in automated way to test too many apps_ . – Bob Snyder Mar 26 '18 at 03:44
  • Or it can be that every time you call `.getToken(mySenderId, "FCM")` it adds another entry and counts it as another app. So maybe find a way to remove all previous tokens. – Pierre Nov 20 '18 at 09:09
  • @Pierre - are you sure this is the case? It wouldn't make sense since Google recommends the app request getId() on app startup. In my experience, FCM simply returns the same id - unless the app has been deleted and reinstalled. – Stinky Towel Nov 27 '18 at 15:32
  • 2
    @StinkyTowel No I am not sure, but then why if my app is literally the only app on my device, It spews this error onto me? What google says sometimes and what actually happens is not always the same. Then this might be a bug on the GCM service. – Pierre Nov 28 '18 at 04:58
  • 9
    is there a way to prevent this from happening? – Salis Nov 23 '19 at 05:37
  • 3
    I have same issue. Actually happened to me twice, I don't use any robot tests, just normal app test so switch a lot between dev/prod version of the app. Factory reset is not an option :( – Anton Sep 26 '21 at 21:49
  • In my case it's coming from real users not from bots. – Rohit Singh Dec 15 '21 at 19:50
  • 2
    I agree with @Anton it is not possible as a developer to factory reset your user's device It's not even possible. – Rohit Singh Dec 15 '21 at 19:51
7

I suspect that these tests are from Google robots, I just published my application and in firebase authentication three logins appear with emails that appear to be fake, such as johnniefernandez.39356@gmail.com. All emails that I suspect are robots end with a period and a number like ".39356" I'm from Brazil and I see through Analytics that the users are from the United States, only 3, so I understand that they are tests, because I haven't published my app for the United States.

  • I’m seeing this issue while uploading my app to the playstore. The automatic testing (pre-launch) start and trigger this error. Yet I’m not able to reproduce locally. I only call getToken() at startup and yes it always returns the same token, unless the token get invalidated by google (very rare). – sonique Jul 01 '21 at 21:51
0

I got these errors reported to firebase crashlytics for my app that is in internal testing, the weird part is it happened to 5 users which is just weird because there's only me who have access to the app. So I think it is probably Google's automated testing bots. Here's the logs

Non-fatal Exception: io.invertase.firebase.crashlytics.JavaScriptError: [messaging/unknown] java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: TOO_MANY_REGISTRATIONS
       at .getToken(address at index.android.bundle:1:905545)
       at .?anon_0_(address at index.android.bundle:1:1790016)
       at .next((native):0:0)
       at .asyncGeneratorStep(address at index.android.bundle:1:65498)
       at ._next(address at index.android.bundle:1:65769)
       at .tryCallOne(InternalBytecode.js:53:16)
       at .anonymous(InternalBytecode.js:139:27)
       at .apply((native):0:0)
       at .anonymous(address at index.android.bundle:1:191460)
       at ._callTimer(address at index.android.bundle:1:190409)
       at ._callReactNativeMicrotasksPass(address at index.android.bundle:1:190573)

Even funnier is, I was not testing the app when these crashes were reported.

Also when I open my app on real devices (low end and high end devices), I don't encounter any of these crashes being reported.

The device info is:

Device
Brand:Google
Model:sdk_goog3_x86_64
Orientation: Portrait
RAM free: 2.01 GB
Disk free: 29.95 GB

Operating System
Version:Android 13
Orientation: Portrait
Rooted:No
aprilmintacpineda
  • 1,114
  • 13
  • 21
0

We've had the same issue, trusting the accepted answer, we deployed to production (fortunately to only 1% of users) and we noticed the problem also happens in real user devices. The solution that worked in my case was to extend FirebaseMessagingService and get the token overriding onNewToken(token: String)

 class PushNotifService : FirebaseMessagingService() {
       ....
       override fun onNewToken(token: String) {
           // Do whatever you need with the token (eg: sending it to the server that will send you notifications)
           super.onNewToken(token)
        }
    }