你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

在 Android 应用程序中添加通话和聊天 SDK

本教程介绍了 Contoso 如何在 Android 应用程序中集成通话和聊天 SDK。

当前限制

Android 通话 SDK 版本早于 2.11.0 时,使用通话和聊天 SDK 生成 Android 应用程序会导致以下错误:

Duplicate class com.skype.rt.XXX found in modules jetified-azure-communication-calling-1.2.0-runtime (com.azure.android:azure-communication-calling:1.2.0) and jetified-trouter-client-android-0.1.1-runtime (com.microsoft:trouter-client-android:0.1.1)

2 files found with path 'lib/x86/libc++_shared.so' from inputs: - …\.gradle\...-azure-communication-calling-1.2.0\jni\x86\libc++_shared.so - …\.gradle\...-trouter-client-android-9.1.1\jni\x86\libc++_shared.so

此问题的导致是由于通话 SDK 包 com.azure.android:azure-communication-calling 中包含的 .jar.so 文件冲突,以及聊天 SDK 包 com.azure.android:azure-communication-chat 导入的传递依赖包 com.microsoft:trouter-client-android

解决方案

从 Android 通话 SDK 版本 2.11.0 开始,Contoso 可以在同一 Android 应用程序中集成通话和聊天 SDK。 这是通过使通话 SDK 依赖于 com.microsoft:trouter-client-android 来实现的,这类似于聊天 SDK 对 Trouter 包的依赖,消除了以前包含在通话 SDK 中的冲突的 .jar 和 .so 文件。

实现步骤

在应用程序的 Gradle 生成文件中指定 Android 通话和聊天 SDK 的版本,如示例所示:

 implementation ('com.azure.android:azure-communication-calling:2.11.0')
 implementation ('com.azure.android:azure-communication-chat:2.0.3') {
     exclude group: 'com.microsoft', module: 'trouter-client-android'
 }

com.azure.android:azure-communication-chat 的版本可以是任何版本。 此处使用最新发布版本作为示例。 但是,需要排除聊天 SDK com.azure.android:azure-communication-chat 附带的 Trouter 包 com.microsoft:trouter-client-android 的版本。 生成应用程序后,将使用通话 SDK 包 com.azure.android:azure-communication-calling 包含的 Trouter 包版本。

后续步骤

GitHub Android QuickStartsAdd-Chat-Calling 文件夹下提供了快速入门示例,另请根据 README.md 了解如何运行示例。