4

I am in the process of updating to the latest Salesforce SDK 6.3.5(Also the same with 6.4.0,latest version) from our old sdk which used GCM.

I have gone through the steps as mentioned below: https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/

  1. The app was already provisioned. Updated the Google FCM server key with the Legacy server key.(This is just to ensure that we still have the right keys)
  2. App was already created on MobilePush portal
  3. Followed these steps for upgrading to FCM:

    https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/sdk-implementation/implement-sdk-google.html

Only few things to note :

  • Already had Firebase integrated as we were using it for Remote Config and also for cloud functions. Since we have to make use of FirebaseMessagingService to handle the cloud function ping, went through this documentation relating to multiple PushSDK

https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/trouble-shooting/multiple-push-sdks.html

  • setSenderId is not set during initialisation phase.
  • Used my own custom FirebaseMessagingService and followed the steps as mentioned in the article

End Results :

App deploys fine, but following things happens:

  • when onRegistrationReceived method is called, systemToken is always null i.e. registration.systemToken() returns null

  • Added all sorts of logging in app including SDKSTATE and log listener to print the details

https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/trouble-shooting/loginterface.html

https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/trouble-shooting/trouble-shooting-push-setup.html

From the logs, i find that the following message keeps appearing :

Message :Failed to retrieve InstanceId from Firebase.
    Sdk Version: 6.3.5
    Google Play Services Version: 12451000
2019-10-28 12:19:09.968 31636-31781/com.example.salesforce D/>>>: Throwable :Attempt to invoke virtual method 'java.lang.String com.google.firebase.iid.FirebaseInstanceId.getToken(java.lang.String, java.lang.String)' on a null object reference

Essentially due to above two issues i.e.

  * Failed to retrieve InstanceId from Firebase.
  * systemToken being null

The connection to FCM is somehow unsuccessful and hence onNewToken method of the custom FirebaseMesasagingService is never called.

Have been through this article as well:

https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/trouble-shooting/trouble-shooting-push-setup.html

In order to test this, we need the pushToken but since that is always null, cannot test it as well.

Have tested sending a push message from the MobilePush portal using the deviceId generated. But in this case, as well, the message is not received.

Some observations:

  • Are we supposed to use Legacy key always?(Since Google is advising against it)

  • Having multiple FirebaseMessagingService.I see that if i implement my own FirebaseMessagingService, from the SDKState logs, there are three including the superclass with different priority

"messagingService":[{"name":"com.example.salesforce.firebaseService.MyFirebaseService","priority":0},
{"name":"com.salesforce.marketingcloud.messages.push.MCFirebaseMessagingService","priority":-1},
{"name":"com.google.firebase.messaging.FirebaseMessagingService","priority":-500}]}},

Some logs that might help:


Listener logs during initialisation

2019-10-28 12:19:09.203 31636-31695/com.example.salesforce D/>>>: status usable:true 2019-10-28 12:19:09.203 31636-31695/com.example.salesforce D/>>>: status loc error :false 2019-10-28 12:19:09.787 31636-31636/com.example.salesforce D/>>>: Message :Unable to retrieve NotificationMessage from Intent (Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.salesforce/com.example.salesforce.view.splashScreen.SplashScreenActivity (has extras) }). Sdk Version: 6.3.5 Google Play Services Version: 12451000 2019-10-28 12:19:09.787 31636-31636/com.example.salesforcee D/>>>: Throwable :Attempt to get length of null array 2019-10-28 12:19:09.853 31636-31636/com.example.salesforce D/>>>: Token is : null

SDKSTATE logs with details of interest:

"PushMessageManager":{"pushEnabled":true,"debugInfo":{"senderId":"XXXXX","deviceToken":null,"firebaseApps":["FirebaseApp{name=[DEFAULT], options=FirebaseOptions{applicationId=1:XXX:android:XXX, apiKey=XXX, databaseUrl=XXX, gcmSenderId=XXX, storageBucket=XXX, projectId=XXX-XXX}}"],"c2dmReceiver":[{"name":"com.google.firebase.iid.FirebaseInstanceIdReceiver","priority":0}],"instanceIdService":[], "messagingService":[{"name":"com.example.salesforce.firebaseService.MyFirebaseService","priority":0}, {"name":"com.salesforce.marketingcloud.messages.push.MCFirebaseMessagingService","priority":-1}, {"name":"com.google.firebase.messaging.FirebaseMessagingService","priority":-500}]}}, "RegistrationManager":{"current_registration":{"deviceID":"XXX","sdk_Version":"6.3.5","app_Version":"X.X.X.X : XXX","dST":false,"location_Enabled":false,"proximity_Enabled":false,"platform_Version":"9","push_Enabled":true,"timeZone":0,"platform":"Android","hwid":"samsung SM-G975F","etAppId":"XXXX-XX","locale":"en_GB","tags":["ALL","Android"],"attributes":[]}},"InAppMessageManager":{"messages":[],"subscriberToken":"null","custom_font_set":false,"status_bar_color":0},"Event":{"triggers":[]}} 2019-10-28 12:19:09.910 31636-31636/com.example.salesforce D/>>>: Device id : XXXXX 2019-10-28 12:19:09.968 31636-31781/com.example.salesforce D/>>>: Message :Failed to retrieve InstanceId from Firebase. Sdk Version: 6.3.5 Google Play Services Version: 12451000 2019-10-28 12:19:09.968 31636-31781/com.example.salesforce D/>>>: Throwable :Attempt to invoke virtual method 'java.lang.String com.google.firebase.iid.FirebaseInstanceId.getToken(java.lang.String, java.lang.String)' on a null object reference

1

If you have implemented our SDK alongside another push provider, to include Firebase's own messaging service, then you must get and handle the token yourself. An example of this can be seen in our "learning application" (ref. https://github.com/salesforce-marketingcloud/MarketingCloudSDK-Android/blob/master/app/src/mpp/java/com/salesforce/marketingcloud/learningapp/MyFcmMessagingService.kt)

If you are not registering with FCM to get a token and providing it to the SDK then the result of getSystemToken() will always be null and there is nothing the SDK can do about your code failing to retrieve a token from Google.

| improve this answer | |
  • Yes that is right. I have used the same setup i.e. creating my own custom FirebaseMessagingService. But the onNewToken method never gets called as i suppose the registration is not successful. Also to add...`the registration to FCM to get a token' , how can i verify this? Looked at the sample code and i have similar setup just unable to figure out why the registration is unsuccessful – Anupama VK Nov 6 '19 at 16:36
  • Sorry, but you're going to have to look to Google/StackOverflow for that help as well as Google's own documentation regarding registering your application to receive push notifications. The Marketing Cloud MobilePush SDK is not handling any of that given your current configuration -- as of right now your question is overly complicated because none of the details are relevant as to why your application is failing to get a token from Google. – Bill Mote Nov 6 '19 at 18:38
  • Thanks for your reply. When faced this issue, i tried 2 approaches: 1. Without custom FirebaseMessagingService i.e. using single push provider i.e. salesforce and setting senderId during init. 2. With custom FirebaseMessagingService as mentioned above In both scenarios, it throws up the same error. Failed to retrieve InstanceId from Firebase. Attempt to invoke virtual method 'java.lang.String com.google.firebase.iid.FirebaseInstanceId.getToken(java.lang.String, java.lang.String)' on a null object reference – Anupama VK Nov 7 '19 at 9:14
  • Am i right in thinking that when using single push provider i.e. salesforce, the salesforce sdk takes care of getting the token? This is why i thought that the integration with the sdk has caused this issue. Although the error points to Firebase but since even on the approach 1, shows the same error. I could also see that 'handleTokenRequest' method being called in salesforce logs. – Anupama VK Nov 7 '19 at 9:14
  • I have been looking at the Firebase stackoverflow,but didnt find anything relevant. I shall post there as well to see if they have any answers for that – Anupama VK Nov 7 '19 at 9:19
0

After trying all possible combinations, i have tried downgrading some of the firebase dependencies and seems like the ML kit version was causing the issue. Not sure why that would be the case. Had the following firebase settings:

  implementation("com.google.firebase:firebase-messaging:20.0.0")
    implementation("com.google.firebase:firebase-core:17.2.") {
        exclude group: 'androidx.annotation'
    }

    implementation("com.google.firebase:firebase-crash:16.2.1") {
        exclude group: 'androidx.annotation'
    }

    implementation("com.google.firebase:firebase-analytics:17.2.0") {
        exclude group: 'androidx.annotation'
    }

    implementation("com.google.firebase:firebase-config:19.0.3") {
        exclude group: 'androidx.annotation'
    }

    implementation("com.google.firebase:firebase-perf:19.0.1") {
        exclude group: 'androidx.annotation'
    }

    implementation ("com.google.firebase:firebase-ml-vision:23.0.0"){
        exclude group: 'androidx.annotation'
    }

Checked with each of the lower versions and found that the versions from 17.0.0 to 21.0.0 work. From 22.0.0 onwards, the FCM token fails to be retrieved.

Unable to figure out the root cause of the issue.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.