Notifiations don't work on Android once built (SDK 41)

Please provide the following:

  1. SDK Version: 41.0.0
  2. Platform: Android

I am working on an app that notifies people of leftover vaccinations in my country. It runs an expo background task which periodically makes a post request to a webpage which retrieves locations and if they have leftover vaccinations. The app is supposed to notify the user when vaccinations are left over. When I debug my app through Expo Go, notifications work fine. However, once my app is built, it doesn’t seem to work. I am very inexperienced with Expo and React Native, but I have followed the instructions on this webpage: Using FCM for Push Notifications - Expo Documentation, but it still does not seem to work, and the instructions are a little unclear to me.

I created my app on Firebase and downloaded the google-services.json, and linked it as such in my app.json. That build didn’t seem to send push notifications. In step 5 of the aforementioned webpage, it mentions to go into GCP and retrieve an API key with no restrictions. I went there and noticed no API keys listed, so I created a new one with no restrictions. I replaced the existing API key in my google-services.json under client.api_key.current_key, with the one I created in GCP, and rebuilt the app. Unforunately, it still does not seem to be working.

I am very inexperienced with Expo and React Native, but the notifications did work when I was testing the app in Expo Go, but not once built, so I think it must be the notifications API that is not working.

As a sidenote, due to how this app is designed, it doesn’t require a server/backend so I skipped that step on the FCM instructions page.

Any help would be greatly appreciated

UPDATE: I just saw this post: Unable to retrieve the FCM server key, which mentions that the command 'expo push:android:show" should check the FCM API key configured for the project. However, when I run the command, I get “Accessing credentials for kjwaller in project TrashVax
There is no FCM API key configured for this project”. I thought I had set this up properly, or am I misunderstanding something?

Your FCM server key should show up there. Follow this step: Uploading Server Credentials and you should be fine.

Thank you so much for the quick reply. I just followed the instructions and the “expo push:android:show” now confirms my FCM key.

Just as an aside, what api key am I supposed to use in the google-services.json file? The one that comes with the generated google-services.json file I download from Firebase, or the one that I see in GCP in the screenshot of my original post.

I’m building it now using the API key from GCP, but I’m not sure how to confirm which is the correct one. I’ll try with both keys regardless, and let you know if that solved it.

Well, I’m experiencing a similar issue: Notifications not working in AAB build: Fetching the token failed: FIS_AUTH_ERROR. Code: E_REGISTRATION_FAILED. - Help: Expo SDK - Forums, but in your case I guess you should use the GCP API key that was auto-generated by Firebase (top one in your screenshot). That one should match the one in your downloaded google-services.json.

edit: If you only have 1 api key (which you do) that one should be in the google-services.json is my guess.

Well, the API key I get from the downloaded google-services.json and the one I created on GCP are different from each other. I just tested the built Android APK using the API key from GCP. I thought it worked, because I got notifications for my test url, but it suddenly stopped working even after reinstalling the APK.

I’m rebuilding it using the google-services.json with the API key from Firebase. Are the 2 API keys from the downloaded google-services.json and GCP supposed to be the same?

From the FCM documentation you linked in your first post:

Note: Firebase will create an API key in the Google Cloud Platform console with a name like Android key (auto created by Firebase) . This is not always the same key as the one found in google-services.json . Always confirm your key and associated restrictions in the Google Cloud Platform console.

Yes, I’ve seen that, it’s just a little unclear to me as I don’t know understand exactly where Firebase and GCP work. I actually just tested out the app using the google-services.json that I got from Firebase where the API key doesn’t correspond with the one I see on GCP, yet it did send me notifications. I’ll just have to see if it continues working or if it stops working after the first try.

Is there any way I can debug a built app to see the error logs or a way to run it through Expo Go using my google-services.json?

Thanks again for your help, I really appreciate it.

Did it sent you notifications in the build you downloaded through app store or locally/dev (expo go/apk installed on device)?

edit: Here’s what I did to troubleshoot my problem for instance.

const [error, setError] = useState<any>();
....
    token = await Notifications.getExpoPushTokenAsync().catch(
        (error) => {
            setError([JSON.stringify(error), `${error}`]);
        }
    );
....
<Text>{error}</Text>

It was locally I guess. I use expo build:android to get a signed APK and use that to install it to my device. I also don’t plan on releasing it on the Google Play store, as I don’t really know how long/difficult/pricey of a process that is. I was going to publish it for download on the github repo.

I tested it on my current phone (OnePlus 7 running Android 11) but I also just dug up an old phone running Android 6, and it even seemed to work on that one.

Should I just take the “If it ain’t broke, don’t fix it” mentality with this one and consider it fixed?

Also, would you recommend I put it on the Google Play store? Are there any benefits to that? I want to put the app out there ASAP as the vaccinations here are ramping up, so it would serve its purpose best the sooner I can put it up.

Publishing it on the play store is not a lot of work. You do need a developer account for it though. How your current APK works doesn’t change at all. You might run into some issues that I am facing but most users don’t want to install an APK that is not from the Play Store. Totally up to you =)

I just looked into it, unfortunately it requires a credit card (which I don’t have) to pay the registration fee.

But it works, and I’m very happy it does. Thanks so much for your help and your speedy replies. I hope you can get around to getting your issue fixed soon.

Happy I could be of help! Good luck with your app!

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.