为了获取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 :(得分:0)
了解如何安装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")
})
}
}
答案 1 :(得分:0)
您正在使用“ com.github.tinder.scarlet”,它是猩红色库的先前groupId。
现在猩红色库已移至Maven Central,您应使用“ com.tinder.scarlet”作为groupId。
“ com.github.tinder.scarlet”按开发中的猩红色包分组,因此您不应该使用它,因为它不稳定。 “ com.github.tinder.scarlet:scarlet:0.2.4”正在开发中,所以不要使用它。
您可以在here
中找到有关Scarlet lib的其他工件答案 2 :(得分:0)
<tr *ngFor="let priceRowData of SolutionsDetail">
<ng-container *ngFor="let group of priceRowData.groups">
<ng-container *ngFor="let requestDetail of group.requestDetails">
<td>{{requestDetail.ReqId}}</td>
</ng-container>
</ng-container>
</tr>
之所以发生这种情况,是因为一个依赖项来自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)
,另一个依赖项来自com.tinder.scarlet
。
com.github.tinder.scarlet
-是其发行版本
com.tinder.scarlet
-他们在说com.github.tinder.scarlet
我做了很多尝试,通过从gradle文件中的依赖项中排除它来解决它,但是它不起作用。
因此,最后我要做的是,将We are working on a new version of Scarlet that supports other persistent connection protocols: ServerSentEvent, Socket IO, STOMP, and MQTT. It can be found on the 0.2.x branch
放入gradle文件中,然后将其文件复制粘贴到项目中的implementation 'com.tinder.scarlet:scarlet:0.1.9'
,websocket
和rxFactory
中。
我知道这不是推荐的方法,但是它可以完成我的工作。
答案 3 :(得分:0)
我使用了版本2,它正在运行。导入您的gradle :)
packagingOptions {
exclude 'META-INF/io.netty.versions.properties'
exclude 'META-INF/INDEX.LIST'
}
implementation 'com.github.tinder.scarlet:scarlet:0.2.4'
implementation 'com.github.tinder.scarlet:scarlet-protocol-websocket-okhttp:0.2.4'
implementation "com.github.tinder.scarlet:scarlet-stream-adapter-rxjava2:0.2.4"
implementation "com.github.tinder.scarlet:scarlet-message-adapter-moshi:0.2.4"
答案 4 :(得分:0)
通过像这样github issue那样定义依赖项,我可以使它正常工作而没有错误:
implementation "com.tinder.scarlet:scarlet:$libVersions.scarlet"
implementation "com.tinder.scarlet:websocket-okhttp:$libVersions.scarlet"
implementation "com.tinder.scarlet:lifecycle-android:$libVersions.scarlet"
implementation "com.tinder.scarlet:message-adapter-gson:$libVersions.scarlet"
implementation "com.tinder.scarlet:stream-adapter rxjava2:$libVersions.scarlet"
libVersions = [
scarlet: '0.1.9'
]
答案 5 :(得分:0)
我使用了这些依赖关系,并且运行正常
implementation group: 'com.tinder.scarlet', name: 'scarlet', version: '0.1.10'
implementation group: 'com.tinder.scarlet', name: 'message-adapter-moshi', version: '0.1.10'
答案 6 :(得分:0)
您应该使用:
implementation "com.tinder.scarlet:scarlet:0.1.9"
implementation "com.tinder.scarlet:websocket-okhttp:0.1.9"
没有猩红色前缀