4

I am trying to send FCM notifications (between users on sending messages, friend requests etc.) in release app which is not receiving but they are sending/receiving very well in debug apk, i have searched about this and found some solutions which are not working for me

like this, I placed it in pro-guard rules but not working

 -keep class com.google.firebase.* {*;}

In my AndroidManifest.xml

        <service
            android:name=".notifications.MyFirebaseMessaging"
            android:enabled="true"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

        <service
            android:name=".notifications.MyFirebaseInstanceId"
            android:enabled="true"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>

and other dependencies, I am not including them here as the app is work fine in debug mode

Edited

I already have

  1. Generated Release SHA-1 and SHA-256 keys
  2. Add them in firebase console
  3. Also added Google console app-signing SHA-1 and SHA-256 keys in firebase
  4. Then download the Google-services.json file and add it in app module

enter image description here enter image description here

mr. groot
  • 334
  • 4
  • 18

3 Answers3

8

You have not added your SHA-1 key for the release to your firebase console and hence not existing in your google-services.json.

  1. Generate your SHA-1 for release
  2. Add your release SHA-1 to firebase console
  3. Download and use new google-services.json.

If you're using Google play app-signing. Make sure the key being used by play store to sign your releases is also added in step 2

  • i have tried your solution step by step but it did not worked for me, tell me any other solution. – mr. groot Dec 29 '20 at 13:13
  • Thank you to tell me the steps for the answer . – mr. groot Dec 30 '20 at 12:04
  • Is it really neccessary to have the SHA fingerprint in Firebase? In the [docs](https://firebase.google.com/docs/cloud-messaging/android/first-message) they explicitely states that this is optional. `(Optional) Enter other app information: App nickname and Debug signing certificate SHA-1.` – Bonco Aug 02 '22 at 09:37
4

Well i found the solution of the problem by my own during brushing my teeth last night. both the answers helped me a lot by guiding me that i need a SHA keys for the release version as i don't know about them so they are very helpful for me.

I have successfully generated SHA keys and store them in firebase console but the notifications was still not working, so i observe that i did not allow to access firebase notification services by the Proguard Rules so i just add this line there

 -keepclassmembers class com.example.app.notifications.* {
      *;
    }

Now it is working magically.

mr. groot
  • 334
  • 4
  • 18
  • What is this app.notifications.*? Can you elaborate more? – Dayanand Lande Aug 30 '22 at 04:55
  • Thank you for this. This led me to fixing my proguard issues, too: - keepclassmembers class com.example.app.notifications.* {*;} (the classes I was using to parse internal notification data) – isles1217 Jul 07 '23 at 22:26
1

Have you got SHA-1 key from right jks file path ?

Priyanka
  • 1,791
  • 1
  • 7
  • 12
  • i don't know the path is right or not but where should it be ? – mr. groot Dec 29 '20 at 06:58
  • For debug , there is a different SHA-1 key and for released there is a different one. For released you need to create a jks file and then you need to add that file's path while creating SHA-1 for released one. – Priyanka Dec 29 '20 at 07:02
  • i Found my key here C:\Users\SRT\Desktop\TeamUp key\key.jks – mr. groot Dec 29 '20 at 07:12
  • You need to get SHA-1 key with following command keytool -list -v -keystore C:\Users\SRT\Desktop\TeamUp key\key.jks -alias name – Priyanka Dec 29 '20 at 07:22
  • hey i'm sorry but i did not get it, i am adding an image of generate signed bundle or apk form in question then please take a look at that and tell me what is missing there – mr. groot Dec 29 '20 at 07:29
  • This is generating signed apk, I am talking about SHA-1 generation for signed apk – Priyanka Dec 29 '20 at 07:55
  • and how can i generate that SHA-1 for signed apk you are talking about, please help – mr. groot Dec 29 '20 at 08:12
  • 1
    You can check this link https://stackoverflow.com/questions/15727912/sha-1-fingerprint-of-keystore-certificate – Priyanka Dec 29 '20 at 08:16
  • hey yes you are right i don't have a sha1 key for release , i tried to get it by the link you shared but did not found and also i tried with signing release but there is only AndroidDebugKey and for release variant it show none. – mr. groot Dec 29 '20 at 09:20
  • hey @Priyanka i have added the release sha1 to firebase console but notifications still not working. – mr. groot Dec 29 '20 at 12:52
  • Thank you so much for helping and tell me the right direction to the answer. – mr. groot Dec 30 '20 at 12:03
  • yes priyanka, you helped me a lot Thanks again. ❤ – mr. groot Dec 30 '20 at 12:14