Firebase Cloud Messaging not working on Release mode (FCM)

RamAkkireddyRamAkkireddy USMember ✭✭

I'm using the FCM for push notifications. Its perfectly working in Debug mode but not working in Release after I signed with KeyStore.

Posts

  • RonnieCyrierRonnieCyrier USMember ✭✭

    I'm getting the same issue. Any updates?

  • ShaktiSriShaktiSri USMember ✭✭

    @RamAkkireddy and @RonnieCyrier I'm facing the same issue. Did you manage to find a solution ?
    Thanks in advance.

  • AlbertKAlbertK MYMember ✭✭✭✭
    edited June 2017

    @ShaktiSri What error message are you getting? Can you post it here?

  • ShaktiSriShaktiSri USMember ✭✭

    I released the app in Ad Hoc and sent a notification from Firebase Console.
    It prompts "Unfortunately App has been stopped." - When the app is not running and also when the app is running.

  • AlbertKAlbertK MYMember ✭✭✭✭

    @ShaktiSri You need to do the following

    1) plug in your phone to your PC with USB cable
    2) VS Menu -> Tools -> Android -> Android ADB command prompt
    adb shell
    logcat | grep AppName
    (the AppName is the name that is found in VS Menu -> Project -> Appname Properties ->Android Manifest ->Package name
    3) Run you notification
    4) Get the output from the crash and post it here.

  • RamAkkireddyRamAkkireddy USMember ✭✭

    @ShaktiSri what adhoc version you are talking about?? You mean release version with KeyStore??
    May be you have set different methods of fetching the info when received the notification. So because of that application is getting crashed. If you can post snippet of the code, may be we can suggest. My issue with the FCM Key in my API as well as .json file updattion. I have done all correctly and it worked

  • ShaktiSriShaktiSri USMember ✭✭

    Yeah, Release Version with KeyStore.
    Just trying to get some general push notification.

  • RamAkkireddyRamAkkireddy USMember ✭✭

    Your code please

  • ShaktiSriShaktiSri USMember ✭✭

    Output from adbshell is attached.
    Thanks in advance

  • RamAkkireddyRamAkkireddy USMember ✭✭

    //


    // This class is the Service class for Sending Push Notification.
    //

    [Service]
    [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
    public class PushNotificationPusher : FirebaseMessagingService
    {
    //Constant value string for firebase message service
    public const string TAG = "MyFirebaseMsgService";
    private AppPreferences prefMan;

        //Method to receive message
        //Pass param messsage to send notification
        public override void OnMessageReceived(RemoteMessage message)
        {
            Log.Debug(TAG, "Message from Push: " + message);  
            prefMan = new AppPreferences();
            prefMan.SetIntPreference("unread_notification_count", int.Parse(message.Data["notification_count"]));
            SendNotification(message.Data["orderid"], message.Data["message"], message.Data["job_type"], message.Data["shipmentstatus"]);
    
        }
    
        //Method to send notification
        //Pass param message body and title to send notification
    
        public void SendNotification(string orderId, string messageBody, string jobType, string status)
        {
            var orderActivity = new Intent(this, typeof(ShipmentsDetailsActivity));
            orderActivity.AddFlags(ActivityFlags.ClearTop);
            prefMan.SetStringPreference(Constants.PREFER_ORDER_ID, orderId);
            prefMan.SetStringPreference(Constants.JOB_TYPE,jobType);
            var pendingIntent = PendingIntent.GetActivity(this, 0, orderActivity, PendingIntentFlags.OneShot);
            ShowNotification(messageBody, pendingIntent);
    
        }
    

    this kind of code???

  • AlbertKAlbertK MYMember ✭✭✭✭

    @ShaktiSri Do you have Proguard enabled? If so, disable it and see if it works.

  • ShaktiSriShaktiSri USMember ✭✭

    @AlbertK I tried that. Didnt worked.

  • AlbertKAlbertK MYMember ✭✭✭✭

    @ShaktiSri Do you actually untick the VS Menu ->Appname Properties -> Android Options -> Packaging -> Enable Proguard ?

    Also do a VS Menu -> Build -> Clean Solution

  • ShaktiSriShaktiSri USMember ✭✭

    @AlbertK Yes I did. I unchecked the "Enable Proguard"

  • AlbertKAlbertK MYMember ✭✭✭✭

    @ShaktiSri From the screenshot you attached, it clearly shows that the app cannot find class "com.google.firebase.iid...."

    Clean Solution and rebuild the Archive again. Sometimes it does happen when you cancel the Archive build half way then rebuild again some files will not be included.

  • Xami3Xami3 PKMember, University ✭✭✭

    @ShaktiSri what is linker behavior? is it set to sdk only?

  • ShaktiSriShaktiSri USMember ✭✭

    @Xami3 : Yes SDK Assemblies Only.

  • ShaktiSriShaktiSri USMember ✭✭

    @AlbertK said:
    @ShaktiSri From the screenshot you attached, it clearly shows that the app cannot find class "com.google.firebase.iid...."

    Clean Solution and rebuild the Archive again. Sometimes it does happen when you cancel the Archive build half way then rebuild again some files will not be included.

    Will Give A Try Again. Thank you

  • Xami3Xami3 PKMember, University ✭✭✭

    @ShaktiSri ok you can change it to link no essembly, just for test. let see if can find the file

  • RonnieCyrierRonnieCyrier USMember ✭✭

    @ShaktiSri said:
    @RamAkkireddy and @RonnieCyrier I'm facing the same issue. Did you manage to find a solution ?
    Thanks in advance.

    my problem revolved around using pro guard. I'm on vacation right now, but found some notes. After some trying, I was able to trap the error and this solved it. Look at the solution and my comment. I used notepad++ to save the cig file.

  • Xami3Xami3 PKMember, University ✭✭✭

    @shakti please add this line to your proguard.cfg file

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

    as your are using proguard in release mode, it removed the following class

    com.google.firebase.iid.FirebaseInstanceIdReceiver

    this was the error

    java.lang.RuntimeException: Unable to instantiate receiver com.google.firebase.iid.FirebaseInstanceIdReceiver: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceIdReceiver"

  • ShaktiSriShaktiSri USMember ✭✭

    @Xami3 said:
    @shakti please add this line to your proguard.cfg file

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

    as your are using proguard in release mode, it removed the following class

    com.google.firebase.iid.FirebaseInstanceIdReceiver

    this was the error

    java.lang.RuntimeException: Unable to instantiate receiver com.google.firebase.iid.FirebaseInstanceIdReceiver: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceIdReceiver"

    Thank you so much for the help.
    It works. ;);)

  • RamAkkireddyRamAkkireddy USMember ✭✭

    Finally..Great help from @Xami3 and hopefully @ShaktiSri is HAPPY :smiley:

  • Hello All,

    I ran into this same issue with our Release build for Google Play.
    Notifications through FCM works fine in Ad-Hoc builds.
    The difference for me is that I am not using Proguard so I'm not seeing the same errors highlighted above.
    Any help would be appreciated!

    Thank you,
    Dinesh

  • RamAkkireddyRamAkkireddy USMember ✭✭

    @DineshNithiyeswaran Have you added signature of release keystore in FCM console?

  • Thank you for replying @RamAkkireddy!
    Yes, I figured this out right after my post.
    You are correct, I was missing the certificate fingerprint in the FCM console

  • IgnasBagdonasIgnasBagdonas LTMember ✭✭
    edited November 2017

    I have the same problem with Google Play. Now, I am added finger print to FCM console and whats next?
    Should I release my app again? Because app still not working. The same apk: adhoc ok, Google play fail.

    EDIT: Ok, I see that google-services.json was changed after finger print adding. So I have replace my old google-service.json and release the new app version?

  • SbastienMedelSbastienMedel USMember ✭✭

    Hello, I have the same problem as you guys, for me the registration is even not working.

    What i've tried is: 1. Debug Mode 2. Put all constants for production 3. Debug the app. This works very well.

    When trying release mode, it's not working.
    How can i debug in release mode, or how can i see logs of what happen?

    I've tried what @AlbertK said but i'm not familiar with this, should my app be started while connected through USB cable ? Should i put debug mode or release mode and launch the app from visual studio ? I dont get it sorry.

    I'm not using proguard, and i don't even use that proguard.cfg file ?

    I'm not even using this package : com.google.firebase.iid.FirebaseInstanceIdReceiver (a consultant came and told me that it's not necesary). My code is a mix between GCM and FCM, i don't get what he did.

    Is there something wrong?

    I'm a bit lost to be honnest.

  • SbastienMedelSbastienMedel USMember ✭✭

    I can't post images of my code...

  • SbastienMedelSbastienMedel USMember ✭✭

    My AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="packageName" android:installLocation="auto" android:screenOrientation="portrait" android:versionCode="1" android:versionName="1.0.0"> <uses-sdk android:minSdkVersion="15" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" /> <application android:label="Appname" android:icon="@drawable/ic_launcher" android:theme="@style/Appname" android:largeHeap="true"></application> </manifest>

  • SbastienMedelSbastienMedel USMember ✭✭

    GcmService.cs

    public static void Register(Context context)
                {
                    try
                    {
                        // Makes this easier to call from our Activity
                        GcmClient.Register(context, GcmBroadcastReceiver.SENDERIDS);
                    }
                    catch (Exception ex)
                    {
                        ex.Data["method"] = "GcmService.Register();";
    
                        Console.WriteLine("Unable to register GCMClient" + ex);
                    }
                }
    

    PushNotificationRegistrationService.cs

        if (_connectionService.IsConnected())
                        {
                            var azureNotificationHubRegistrationId = _settings.GetValueOrDefault(UserSettingConstants.AzureNotificationHubRegistrationId, string.Empty);
                            if (string.IsNullOrEmpty(azureNotificationHubRegistrationId))
                            {
                                azureNotificationHubRegistrationId = await _notificationService.GetRegistrationIdToken(deviceRegistration.PnsHandle);
                                _settings.AddOrUpdateValue(UserSettingConstants.AzureNotificationHubRegistrationId, azureNotificationHubRegistrationId);
                            }
    
                            _settings.AddOrUpdateValue(UserSettingConstants.PnsHandle, deviceRegistration.PnsHandle);
    
                            await _notificationService.CreateOrUpdateDeviceRegistration(azureNotificationHubRegistrationId, deviceRegistration);
                        }
    
    GcmBroadcastReceiver.cs
    
                    [BroadcastReceiver(Permission = Gcm.Client.Constants.PERMISSION_GCM_INTENTS, Name = "PackageName.GcmBroadcastReceiver")]
                    [IntentFilter(new[] { Intent.ActionBootCompleted })] // Allow GCM on boot and when app is closed   
                    [IntentFilter(new[] { Gcm.Client.Constants.INTENT_FROM_GCM_MESSAGE }, Categories = new string[] { "PACKAGE_NAME" })]
                    [IntentFilter(new[] { Gcm.Client.Constants.INTENT_FROM_GCM_REGISTRATION_CALLBACK }, Categories = new string[] { "PACKAGE_NAME" })]
                    [IntentFilter(new[] { Gcm.Client.Constants.INTENT_FROM_GCM_LIBRARY_RETRY }, Categories = new string[] { "PACKAGE_NAME" })]
    
                    public class GcmBroadcastReceiver : GcmBroadcastReceiverBase<GcmService>
                    {
                        public static string[] SENDERIDS = { Constants.AppConstants.SenderId };
                        public const string TAG = "GCM";
                    }
    
  • ioannismanuelioannismanuel Member
    edited February 2018

    In my Situation I Just unchecked proguard checkbox in android project-> android Options->packaging properties and it works like a charm!!!, I left a link bellow!!!

  • michaelitohmichaelitoh USMember ✭✭

    @RamAkkireddy said:
    @DineshNithiyeswaran Have you added signature of release keystore in FCM console?

    It's works for me. Thanks.

  • JulioMoontenegroJulioMoontenegro USMember

    I had to add the following lines into my proguard file and firebase works well on release mode.

    -keep class com.google.firebase.** { *; }
    -keep class org.apache.** { *; }
    -keepnames class com.fasterxml.jackson.** { *; }
    -keepnames class javax.servlet.** { *; }
    -keepnames class org.ietf.jgss.** { *; }
    -dontwarn org.apache.**
    -dontwarn org.w3c.dom.**

  • LofiMAMLofiMAM Member ✭✭
    edited July 30

    I just came :) now from my fight with this issue;
    the solution to make notifications work on release mode:
    right click on android project -> properties -> Android Options -> skip linking assemblies -> add "Plugin.FirebasePushNotification" to it;

    explain problem cause (you do not need to read that):
    the stupid, unnecessary, not useful, and ugly xamarin linking remove unused java byte code after finish building the application on release mode, some of this removed code is our library :):):):):):) ,
    So you have to command it to keep it by following the solution that explain it above;

Sign In or Register to comment.