注册

【手把手教Android聊天室uikit集成-kotlin 第一期】

前言:环信提供一个开源的 ChatroomUIKit 示例项目,演示了如何使用该 UIKit 快速搭建聊天室页面,实现完整业务。

本文展示如何编译并运行 Android 平台的聊天室 UIKit 示例项目。

#

一、详细步骤导入uikit
二、遇到集成报错解决 
1. 从github下载的附件我们打开以后 会有两个 一个是ChatRoomService ,另外一个是ChatroomUIKit
25f89f1afe7c9e22b32f5ee333482a7e.jpg
2.先倒入UIkit的本地库(引导的内容可以参考标题1. 的绿色箭头第二个文件夹)
4b686091d39c6c814c96c9671610f49a.png
3.然后在导入ChatRoomservice 选择文件后也点击Finish 注: 一共两个文件 都需要导入
22ffa4be19d8e9a0d28dd515eda10012.png
4.填写settings.gradle
include(":ChatroomUIKit")
include(":ChatroomService")
bf3727ee5a39b1e2f22d4b926c7645c5.png
5.添加:build.gradle(app)
implementation(project(mapOf("path" to ":ChatroomUIKit")))
615436cabc946f2940e9bb2a647b23aa.png
6.如果遇到该报错如下:
遇到报错如下:
Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it to compile against version 34 or later of the Android APIs.
:app is currently compiled against android-33.
Also, the maximum recommended compile SDK version for Android Gradle
plugin 7.4.2 is 33.
Recommended action: Update this project's version of the Android Gradle
plugin to one that supports 34, then update this project to use
compileSdkVerion of at least 34.
Note that updating a library or application's compileSdkVersion (which
allows newer APIs to be used) can be done separately from updating
targetSdkVersion (which opts the app in to new runtime behavior) and
minSdkVersion (which determines which devices the app can be installed
解决方案: 注意一下自己app的 targetSDK版本号以及compilesdk 都给到 34 大概在报错信息也能提示到是 需要强制到34
7.初始化UIkit
0650177b4e1be160ea88ebe1369dfb19.png
(1)appkey管理后台位置
b921be511741f7e43bd5720dc32c5cd9.png
8.客户端登录调用
ChatroomUIKitClient.getInstance().login("4","YWMtFTJV-OXGEe6LxEWLvu_JdPqlsNlfrUUAh3km7oObq2HVh7Pgj9ER7JuEZ0XLQ13UAwMAAAGOVbV_AAWP1AB9sFv_7oIlDyK7Jay0Coha-HnF5o0PnXttL7r4gxryCA", onSuccess = {
val intent = Intent(this@MainActivity, As::class.java)
startActivity(intent)

}, onError = {
code, error ->


})

b9d10f8757c036c5d48c68014b5b5986.png

(1)参数管理后台具体位置 ,每次点击查看token的token内容都是不同的,这个不必担心。
7345dd745a4e9f25363672f15f74f312.png

(2)跳转到Asactivity 后遇到了一个问题!
继承ComponentActivity() 无法拿到setContent
解决办法:将这个依赖升级到 1.8.0 刚才用了1.7.0版本 无法拿到这个setContent
implementation("androidx.activity:activity-compose:1.8.0")
9.展示进入聊天室逻辑
class As : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent{
ComposeChatroom(roomId = "242681589596161",roomOwner = UserInfoProtocol)
}
(1)参数roomId 在管理后台可以查看
f17c7b8b82e1777c1c7c0b48e8f7e6ee.png
(2)roomOwner 为 UserInfoProtocol 类型 ,可以自己定义编辑属性将参数存入方法内
8afbf0c38287fe87a957d1bf0f34ff8a.png

0 个评论

要回复文章请先登录注册