Prashanth
Prashanth

Reputation: 21

Android Azure notification hub SDK is not working in Android Pie

Android Azure notification hub SDK is not working in Android Pie.

Below are the SDK details:

mavel url: "http://dl.bintray.com/microsoftazuremobile/SDK"

dependencies:

compile 'com.microsoft.azure:notification-hubs-android-sdk:0.4@aar'

compile 'com.microsoft.azure:azure-notifications-handler:1.0.1@aar'

Steps to reproduce:

  1. Receive GCM/FCM token

  2. Create instance of NotificationHub

  3. Call method "registerTemplate" using the instance of NotificationHub along with the required parameters.

Error:

Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/net/http/AndroidHttpClient;
        at com.microsoft.windowsazure.messaging.Connection.executeRequest(Connection.java:217)
        at com.microsoft.windowsazure.messaging.Connection.executeRequest(Connection.java:178)
        at com.microsoft.windowsazure.messaging.Connection.executeRequest(Connection.java:134)
        at com.microsoft.windowsazure.messaging.NotificationHub.refreshRegistrationInformation(NotificationHub.java:296)
        at com.microsoft.windowsazure.messaging.NotificationHub.registerInternal(NotificationHub.java:390)
        at com.microsoft.windowsazure.messaging.NotificationHub.registerTemplate(NotificationHub.java:196)

Upvotes: 0

Views: 1647

Answers (3)

Andrew Marshall
Andrew Marshall

Reputation: 71

This has been fixed in the 0.5 version of Azure Notification Hub Android SDK.

Update your Azure dependency to:

implementation 'com.microsoft.azure:notification-hubs-android-sdk:0.5@aar'

This version uses HttpUrlConnection instead of the legacy HttpClient. See pull request: https://github.com/Azure/azure-notificationhubs/pull/48

Upvotes: 1

Prashanth
Prashanth

Reputation: 21

Currently in Android Pie the reference for httpclient has removed completly from system ClassLoader. Above issue can be fixed if we add the httpclient as a part of application ClassLoader. I have added

<uses-library android:name="org.apache.http.legacy" android:required="false" /> 

inside application tag of manifest file, it's working now. For more information please refer below link: https://developer.android.com/about/versions/pie/android-9.0-changes-28#apache-p

Upvotes: 2

Anubhav Gupta
Anubhav Gupta

Reputation: 2000

Update your Android Support Library to the latest version will fix the problem. Along with that, a clean and rebuild of the project and a restart of Android Studio could also help.

Upvotes: 2

Related Questions