5

I had an app using Firebase and GMS service with version 11.8.0 for 2 years and now, I want to upgrade to latest version is 17.0.0. The dependencies following by below in gradle:

Before upgrade:

implementation 'com.google.firebase:firebase-core:11.8.0'
implementation 'com.google.android.gms:play-services-location:11.8.0'
implementation 'com.google.android.gms:play-services-base:11.8.0'
implementation 'com.google.firebase:firebase-invites:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.google.firebase:firebase-config:11.8.0'
implementation 'com.google.android.gms:play-services-maps:11.8.0'

After upgrade:

implementation 'com.google.firebase:firebase-analytics:17.2.3'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-base:17.1.0'
implementation 'com.google.firebase:firebase-invites:17.0.0'
implementation 'com.google.firebase:firebase-messaging:20.1.1'
implementation 'com.google.firebase:firebase-config:19.1.2'
implementation 'com.google.android.gms:play-services-maps:17.0.0'

And modify code from:

    public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

        @Override
        public void onTokenRefresh() {
            //Getting registration token
            String token = FirebaseInstanceId.getInstance().getToken();
            // Save token
        }
    }

To

public class MyFirebaseInstanceIDService extends FirebaseMessagingService {

    @Override
    public void onNewToken(@NonNull String s) {
        super.onNewToken(s);
        // Save token
    }
}

And in Manifest I keep register service as below:

<service android:name=".notification.MyFirebaseInstanceIDService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

Everything else I setup before is no change. But when build and run I take an error with below stacktrace:

2020-03-12 11:38:29.225 26475-26543/com.example E/FirebaseInstanceId: Topic sync or token retrieval failed on hard failure exceptions: FIS_AUTH_ERROR. Won't retry the operation.
2020-03-12 11:38:29.460 26475-26550/com.example 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:61)
        at com.google.android.gms.tasks.Tasks.await(Unknown Source:23)
        at com.google.firebase.iid.zzs.zzb(com.google.firebase:firebase-iid@@20.1.0:54)
        at com.google.firebase.iid.zzs.zza(com.google.firebase:firebase-iid@@20.1.0:89)
        at com.google.firebase.iid.zzv.run(Unknown Source:12)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
     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(Unknown Source:0)
        at com.google.firebase.installations.FirebaseInstallations$$Lambda$1.run(Unknown Source:2)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:919) 

After looking for solution on google, i found something like this: https://firebase.google.com/support/release-notes/android#2020-03-03

Then I go to my firebase console and enable Firebase Installation but nothing change. So can someone help me find out the way to resolve this issue? Many thank to all!

MMG
  • 3,226
  • 5
  • 16
  • 43
Shaw
  • 105
  • 1
  • 1
  • 6

3 Answers3

7

change firebase-messaging version to 20.1.0

implementation 'com.google.firebase:firebase-messaging:20.1.0'
Nensi Kasundra
  • 1,980
  • 6
  • 21
  • 34
3

Downgrading the firebase-messaging library is not a recommended solution.

As of v20.1.1 of Firebase cloud messaging and 20.1.0 of Firebase InstanceId, these libraries depends on the Firebase installations SDK. This make things a little bit different than before.

For instance if you use FirebaseOptions and not a google-services.json file to intialize these libraries, you need extra information to pass to FirebaseOptions.

According to the release note:

Apps that use the Firebase auto-initialization process and the Gradle plugin to convert google-services.json into resources are unaffected. However, apps that create their own FirebaseOptions instances must provide a valid API key, Firebase project ID, and application ID.

Reference: Firebase android release note

TL; DR

So to sum up, you should look for breaking changes that affect your code and update them the way the latest version supports.

Mahdi-Malv
  • 16,677
  • 10
  • 70
  • 117
  • 1
    Thanks for your support, i resolved it by downgrading version as you said, it's so hard for a day. – Shaw Apr 07 '20 at 08:28
  • 2
    @Shaw I think you misunderstood. The recommendation is not to downgrade. – Big McLargeHuge Apr 10 '20 at 20:29
  • @Shaw That's exactly the first line. – Mahdi-Malv Apr 11 '20 at 04:24
  • @Mahdi-Malv This is not right. My app used Firebase auto-initialization process and the Gradle plugin to convert google-services.json into resources. However, they're affected and demand the initialization with FirebaseOptions. Can you suggest what might be causing this error? – Mashal Rashid May 04 '20 at 10:44
  • What I quoted was FCM release note. Perhaps json file should be refreshed from firebase console. Open it up and see all data exist (apiKey, applicationId, etc). If they do, you may want to contact fcm or ask a question yourself and then add firebase tag or mention one of firebasers. – Mahdi-Malv May 04 '20 at 19:03
0

Firebase Android SDK updates on February 27 (M65) and afterwards introduced a new infrastructure service, the Firebase Installations SDK which comes with a dependency on the Firebase Installations API.
Firebase Installations requires valid Firebase options API key, project ID, and application ID (a.k.a. "appId") in order to successfully communicate with Firebase servers.

Errors during communication with the Firebase Installations API indicate invalid Firebase options or misconfigurations regarding API keys.

To mitigate the issue

  • make sure that your application is using valid Firebase options from the latest google-services.json file from your Firebase console: Firebase options: instructions and background.
  • If you use API restrictions, make sure that the API key used by your application is white-listed for the Firebase Installations API (and for your application): API restrictions: instructions and background
  • Regarding Application restrictions: Either set the radio button to None or make sure that your app is white-listed (with the correct SHA-1 certificate).

For details, please visit:
https://firebase.google.com/support/privacy/init-options

Andreas Rayo Kniep
  • 5,674
  • 2
  • 30
  • 30