Firebase-android-sdk: FirebaseInstanceId.getInstanceId() failing with SERVICE_NOT_AVAILABLE on WearOS device connected to iPhone

Created on 7 Dec 2018  路  12Comments  路  Source: firebase/firebase-android-sdk

Describe your environment

  • Android Studio version: 3.2
  • Firebase Component: Firebase Core & Cloud Messaging
  • Component version:
    firebase_core: "16.0.4",
    firebase_perf: "16.2.0",
    firebase_messaging: "17.3.4",
    firebase_crashlytics: "2.9.6",
    firebase_plugins: "1.1.5",
    firebase_inappmessaging: "17.0.3",
    firebase_config: "16.1.0",

Describe the problem

WearOS devices connected to an iPhone recently started getting SERVICE_NOT_AVAILABLE errors when calling FirebaseInstanceId.getInstanceId(). The exact exception is:

2018-12-07 14:37:26.529 5093-5093/com.xxxxx.xxxxxx E/OurFirebaseActivity: Could not get Firebase token. Exception: java.io.IOException: SERVICE_NOT_AVAILABLE
    java.io.IOException: SERVICE_NOT_AVAILABLE
        at com.google.firebase.iid.zzr.zza(Unknown Source:66)
        at com.google.firebase.iid.zzr.zza(Unknown Source:79)
        at com.google.firebase.iid.zzu.then(Unknown Source:4)
        at com.google.android.gms.tasks.zzd.run(Unknown Source:5)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)

This doesn't seem to be specific to our app only, when looking at the device logs, this seems to happen for other apps/services as well.

2018-12-07 14:02:48.931 891-3870/? I/GCM: Registration for wearable paired to iOS
2018-12-07 14:02:48.956 857-857/? D/AltFCMManager: reading APNS_TOKEN dataitem found a null dataitem: 
2018-12-07 14:02:49.107 857-881/? I/zygote: Background concurrent copying GC freed 
2018-12-07 14:02:53.950 891-3870/? W/GCM: Timed out getting APNS token from clockwork
2018-12-07 14:02:53.963 4509-4544/? E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE

Steps to reproduce:

Connect Ticwatch Pro to an iPhone device. Update to the latest WearOS version. Try to call FirebaseInstanceId.getInstanceId() and notice SERVICE_NOT_AVAILABLE.

Note that this Ticwatch Pro device is NOT a China Edition (I'd expect Play Services not to work there), and that we're receiving complaints from users with a wide range of WearOS devices. The only common pattern is that they're all connected to an iPhone, and that it all seems to have started in the past week or so.

Also note that interestingly, we are seeing some internal firebase logs tagged with FA-SVC (analytics?) that show a json bundle uploaded to firebase that DOES include a firebase_instance_id property (some data replace with xxxx for privacy):

2018-12-07 14:13:50.811 1281-4717/? V/FA-SVC: Uploading data. app, uncompressed size, data: com.xxxxxxx.xxxxxxx, 375, 
    batch {
      bundle {
        protocol_version: 1
        platform: android
        gmp_version: 13001
        uploading_gmp_version: 14799
        config_version: 1542996287125120
        gmp_app_id: 1:xxxxxxxx:android:xxxxxxxx
        app_id: com.xxxxxxx.xxxxxxx
        app_version: 2.0.0
        app_version_major: 9999
        firebase_instance_id: fLP7soXXXXX
        dev_cert_hash: XXXXXXXXXXXXX
        app_store: manual_install
        ...

Relevant Code:

firebase.instanceId.addOnSuccessListener {
            Log.d("OurActivity", "Token received: " + it.token);
            SimpleRxBackgroundOp(generateQRBitmap, onBitmapReady, onFailure).execute()
        }

/// always fails there with Exception listed above
        firebase.instanceId.addOnFailureListener() {
            Log.e("OurActivity", "Could not get Firebase token. Exception: " + it);
            onFailure.call(it)
        }
core messaging

Most helpful comment

Restarting the emulator or real devices, does works.

All 12 comments

FYI - same exact code works if the WearOS device is connected to an Android phone.

Update: also confirmed that GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) returns SUCCESS on these WearOS/iPhone device combos.

Confirmed this is happening on the template Watch Face generated by Android Studio and by following the steps from Tools > Firebase to connect the sample watch face to Firebase Cloud Messaging. The following code to get the FCM token works on a WearOS device connected to Android, but fails on WearOS connected to iPhone:

FirebaseInstanceId.getInstance().getInstanceId()
                    .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
                        @Override
                        public void onComplete(@NonNull Task<InstanceIdResult> task) {
                            if (!task.isSuccessful()) {
                                Log.w(TAG, "getInstanceId failed", task.getException());
                                return;
                            }

                            // Get new Instance ID token
                            String token = task.getResult().getToken();

                            Log.d(TAG, "Got the token: " + token);
                        }
                    });

The error on WearOS connected to iPhone is:

12-16 16:42:50.201 24627-24627/com.example.ariel.fcmwatchfacetest D/Mywatchface聽service: Getting token...
12-16 16:42:57.404 24627-24627/com.example.ariel.fcmwatchfacetest W/Mywatchface聽service: getInstanceId failed
                                                                                         java.io.IOException: SERVICE_NOT_AVAILABLE
                                                                                             at com.google.firebase.iid.zzr.zza(Unknown Source:66)
                                                                                             at com.google.firebase.iid.zzr.zza(Unknown Source:79)
                                                                                             at com.google.firebase.iid.zzu.then(Unknown Source:4)
                                                                                             at com.google.android.gms.tasks.zzd.run(Unknown Source:5)
                                                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                                                                                             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                                                                                             at java.lang.Thread.run(Thread.java:764)

Restarting the emulator or real devices, does works.

Make sure the device has an internet connection when getting FCM token

@littleariel were you able to find a solution to this problem? I still have this issue even after restarting, and making sure the watch is conneted to the internet. I also find that this is only an issue when the watch is connected to iphone, and works when connected to android

@eambutu on our side, this was actually caused by a bug in the WearOS app for iPhone. It was fixed by version v3.11.27.

oh weird. does it work for you now on the recent versions of the wearOS app? or, would you happen to know any of the details of what bugs were causing this issue?

Yes - it works right now, with the latest version of the WearOS app for iPhone.
I'm not sure what the actual issue was - it was something on the Google side that I didn't have visibility on.

@littleariel were you able to find a solution to this problem? I still have this issue even after restarting, and making sure the watch is conneted to the internet. I also find that this is only an issue when the watch is connected to iphone, and works when connected to android

The problem solved when i connected the watch with Android (and was not working when it was connected with iphone.)

Restarting the emulator or real devices, does works.
Android emulator, thats helpful. Thanks!

Looks like the issue is fixed. Please file a new issue if you experience something different than this.

Was this page helpful?
0 / 5 - 0 ratings