Troubleshoot Initialization Errors on Android

The troubleshooting steps for initialization errors vary depending on the version of the Salesforce Engagement SDK you use.

Version 8 and higher 

The InitializationStatus is provided via the InitializationListener passed into the call to the SFMCSdk’s configure method.

Version 7 

The InitializationStatus is provided via the InitializationListener passed into the call to the SDK’s init method. While this class contains extensive information that can help troubleshoot SDK initialization issues, there are only a limited number of things that you can address at runtime.

This section describes the methods from InitializationStatus that are useful to check at runtime and how you can recover from them. The InitializationStatus is provided via the InitializationListener passed into the call to the SFMC SDK’s configure method.

status()

The status() method returns the status of the initialization call.

locationsError()

If you've configured the SDK to enable either geofence or proximity messaging, locationsError() indicates whether the SDK encountered an issue with the Google Play Service location library. Additionally, you can also use playServicesMessage() and playServicesStatus() to determine the exact action that you must take to resolve this issue. However, the most likely issue is that the device doesn't have a compatible version of Google Play Services installed and you must prompt the user to perform an update.

messagingPermissionError()

messagingPermissionError() indicates that region messaging was unable to be turned on after a restart due to the android.Manifest.permission.ACCESS_FINE_LOCATION or android.Manifest.permission.ACCESS_BACKGROUND_LOCATION no longer being granted. Enabling geofence or proximity messaging requires you to request the runtime permission for location. Then, after you've called the corresponding messaging enablement method (enableGeofenceMessaging or enableProximityMessaging), the SDK will track this setting and check whether the permission is still granted during each initialization. If the user has revoked the location permission from your application, the SDK disables the previously enabled messaging type and requires you to re-request the permission from the user, and re-enable messaging in the SDK.

Example InitializationListener Implementation 

8.x
1SFMCSdk.configure(context.applicationContext as Application, SFMCSdkModuleConfig.build {
2  this.pushModuleConfig = newConfig
3}) {
4  when(it.status) {
5    com.salesforce.marketingcloud.sfmcsdk.InitializationStatus.SUCCESS -> {
6      Log.v("MyApp", "SDK init succeeded")
7    }
8    com.salesforce.marketingcloud.sfmcsdk.InitializationStatus.FAILURE -> {
9      Log.e("MyApp", "SDK init failed")
10    }
11  }
12}
7.x
1MarketingCloudSdk.init(context, config) { status ->
2  when (status.status()) {
3    InitializationStatus.Status.COMPLETED_WITH_DEGRADED_FUNCTIONALITY -> {
4      if (status.locationsError()) {
5        //Handle Google Play Services issues.
6        if (GoogleApiAvailability.getInstance().isUserResolvableError(status.playServicesStatus())) {
7          // User will likely need to update GooglePlayServices through the Play Store.
8          // Call GoogleApiAvailability.getInstance().showErrorDialogFragment(...) from Activity.
9        }
10      } else if (status.messagingPermissionError()) {
11        // User disabled location permission.
12        // Re-request permission and if granted enable desired messaging type
13      }
14    }
15    InitializationStatus.Status.SUCCESS -> Log.v("MyApp", "SDK init succeeded")
16    InitializationStatus.Status.FAILED -> Log.e(
17      "MyApp",
18      "The SDK failed to initialize.  Status: $status",
19        status.unrecoverableException()
20    )
21  }
22}

See Also