Android Azure 通知中心 SDK 在 Android Pie 中不工作

Android Azure notification hub SDK is not working in Android Pie

Android Azure 通知中心 SDK 在 Android Pie 中不工作。

SDK详情如下:

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

依赖关系:

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

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

重现步骤:

  1. 收到GCM/FCM令牌

  2. 创建 NotificationHub 实例

  3. 使用 NotificationHub 实例和所需参数调用方法 "registerTemplate"。

错误:

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)

将您的 Android Support Library 更新到最新版本即可解决问题。除此之外,清理和重建项目以及重新启动 Android Studio 也会有所帮助。

目前在 Android Pie 中,httpclient 的引用已从系统类加载器中完全删除。如果我们将 httpclient 添加为应用程序 ClassLoader 的一部分,则可以解决上述问题。我已经添加

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

在清单文件的应用程序标签内,它现在可以工作了。 更多信息请参考下方link: https://developer.android.com/about/versions/pie/android-9.0-changes-28#apache-p

这已在 0.5 版本的 Azure 通知中心 Android SDK 中修复。

将您的 Azure 依赖项更新为:

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

此版本使用 HttpUrlConnection 而不是旧版 HttpClient。查看拉取请求:https://github.com/Azure/azure-notificationhubs/pull/48