4

I have two android applications. I am using only one firebase project for both of them, with both applications included in it. So I have only one google-services.json with specified keys for both my applications. I am trying to use firebase cloud messaging and I am experiencing following problems:

When I want to test cloud messaging from firebase console I am able to choose to which appId I want to send a message. I have both applications installed on my device. Both are working normally. I have also released them to google play (alpha testing) and everything went well. I am able to download them from store normally. AppId should be set properly (how can I check that?). Problem is, that when I choose the first app in firebase console I am receiving notifications from both apps and when I choose the second app I am receiving nothing.

What can cause these problems? Do I need to create completely new firebase project for the second app, too? Or am I missing something?

If you need to see some code, let me know. At this point I don't know what piece of code could tell you more about my problem.

Matej Košút
  • 590
  • 2
  • 10
  • 27
  • "I have two android applications (flavours)" -- I'm confused. Do you actually mean two different apps (different package names -- this I believe is your case) or different [build variant](https://developer.android.com/studio/build/build-variants)? When testing, were the apps installed in separate devices? Adding more info on the testing scenario would be great. Cheers! – AL. Oct 09 '18 at 17:34
  • Sorry for confusion. I actually have both. I have two apps and both have two build variants (debug and release) - but it is not the case. I see that usage of "flavours" was not right in that description. But the problem is with two apps with two different package names - that is exactly the case. Apps were installed on one, the same device. – Matej Košút Oct 09 '18 at 21:05

1 Answers1

0

It looks like you have used same google service json file on both your apps. So thats why sending cloud notification for one app is received on both apps while in second case since no app has the json file for that there is no notification.

Go to your firebase project settings and download the google services file for both app ( you should first download one and move that file to desired project then download second services file).

Umar Hussain
  • 3,461
  • 1
  • 16
  • 38
  • Yes. I am using the same google-services.json file for both apps. Firebase documentation says that I can have two apps in one firebase project. And one firebase project generates only one google-services.json, doesn't it? Or isn't it possible to have multiple apps in one firebase project? – Matej Košút Oct 09 '18 at 14:32
  • no it generates service files separately for each app. – Umar Hussain Oct 09 '18 at 14:34
  • How can I get the google-services.json file for the second app then? When I switch apps in firebase console -> project settings it is still downloading the same file. google-services.json file is the same for both apps in my console. Weird. – Matej Košút Oct 09 '18 at 14:40
  • select the second app in project and then download it, like the image in below answer – Umar Hussain Oct 09 '18 at 14:43
  • That is exactly what I am doing. It is downloading files with exactly the same content. I checked it right now one more time to be 100% sure. – Matej Košút Oct 09 '18 at 15:09
  • you are seeing two apps in the your apps section? both apps have different app ids – Umar Hussain Oct 09 '18 at 15:11
  • then the downloaded files should not be identical, as the json file has the app id as well. simply delete the all google json services file in your download folder. Then download first app json file. Rename it as app1.json. Then download second rename it to app2.json and then compare. – Umar Hussain Oct 09 '18 at 15:14
  • 1
    I tried all of that. Files are still the same. However the downloaded file google-services.json contains both app ids of both apps. It seems to be some kind of mix of both apps. – Matej Košút Oct 09 '18 at 15:28
  • I need to test this behaviour you are doing every thing right. One more thing the app id in gradle matches the app ids you have declared in firebase console for apps? – Umar Hussain Oct 09 '18 at 15:42
  • Yes, it does. I have two flavours of one project with two appIds, so I tried to use everywhere only one appId (gradle, manifest, ...), I tried to change it everywhere, I tried to change it in google-services.json to be everywhere only one appId. Neither of those helped. – Matej Košút Oct 09 '18 at 15:47
  • what happens if both app will subscribe with same token? In that case does the both app will receive same notification ? – Android Dev Jan 24 '23 at 12:08