gpt4 book ai didi

android - 安装 Scarlet 时重复依赖项

转载 作者:行者123 更新时间:2023-12-02 12:09:38 32 4
gpt4 key购买 nike

为了获得 websocket 模块,我安装了这两个依赖项:

 implementation 'com.tinder.scarlet:scarlet:0.1.9'
implementation "com.github.tinder.scarlet:scarlet-websocket-okhttp:0.1.9"

但是当我构建我的应用程序时,我收到了这个错误:
Duplicate class com.tinder.scarlet.Deserialization found in modules scarlet-core-0.1.9.jar (com.github.tinder.scarlet:scarlet-core:0.1.9) and scarlet-core-0.1.9.jar (com.tinder.scarlet:scarlet-core:0.1.9)
... bunch of other duplicates

如果我删除任何一个,那么我就不能使用这些包,因为我需要两个依赖项。

这是我的连接类:
object Connection {
fun connect() {
val okHttpClient = OkHttpClient.Builder()
.readTimeout(0, TimeUnit.MILLISECONDS)
.build()


val scarletInstance = Scarlet.Builder()
.webSocketFactory(okHttpClient.newWebSocketFactory("ws://url.."))
.build()

val messageService = scarletInstance.create<MessageService>()

messageService.observeWebSocketEvent()
.filter { it is WebSocket.Event.OnConnectionOpened<*> }
.subscribe({
Timber.d("connected to web socket")
})

messageService.observeText()
.subscribe({ text ->
Timber.d("Web socket message: $text")
})
}
}

核心依赖包含 com.tinder.scarlet.Scarlet类,并且 websocket 依赖包含 com.tinder.scarlet.websocket.okhttp.newWebSocketFactory类,我不能没有另一个。

最佳答案

了解如何安装 0.2.x 分支:

我使用了这些依赖项:

implementation 'com.github.tinder.scarlet:scarlet:0.2.4'
implementation 'com.github.tinder.scarlet:scarlet-protocol-websocket-okhttp:0.2.4'

两者都可以在提交时使用当前示例代码: https://github.com/Tinder/Scarlet/tree/45d97cc6d0de537872af789306765715978efecc

新连接对象:
object Connection {
fun connect() {
val okHttpClient = OkHttpClient.Builder()
.readTimeout(0, TimeUnit.MILLISECONDS)
.build()

val protocol = OkHttpWebSocket(
okHttpClient,
OkHttpWebSocket.SimpleRequestFactory(
{ Request.Builder().url("ws://...").build() },
{ ShutdownReason.GRACEFUL }
)
)

val configuration = Scarlet.Configuration()

val messageService = Scarlet(protocol, configuration).create<MessageService>()


messageService.observeWebSocketEvent()
.observeOn(Schedulers.io())
.subscribe({
Timber.d("connected to web socket")
})

messageService.observeText()
.subscribe({ text ->
Timber.d("Web socket message: $text")
})
}
}

关于android - 安装 Scarlet 时重复依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57403233/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com