安装 Scarlet 时重复依赖项

Duplicate dependencies when installing Scarlet

为了获取 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

如果我删除其中任何一个,那么我将无法使用这些包,因为我需要两个依赖项。

这是我的连接class:

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.Scarletclasses,websocket依赖包含com.tinder.scarlet.websocket.okhttp.newWebSocketFactoryclasses,缺一不可。

了解如何安装 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")
            })
    }
}

您正在使用 "com.github.tinder.scarlet",它是 scarlet lib 的前一个 groupId。

现在 scarlet lib 移到了 maven central,你应该使用 "com.tinder.scarlet" 作为 groupId。

"com.github.tinder.scarlet" 是为正在开发的 scarlet 包分组的,所以你不应该使用它,因为它不稳定。 "com.github.tinder.scarlet:scarlet:0.2.4" 正在开发中,所以不要使用它。

您可以在 here

中找到 scarlet 库的其他工件
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 - 他们说 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' 在 gradle 文件中,并复制粘贴他们在 websocketrxFactorygsonFactory 中的文件在我的项目中。 我知道这不是推荐的方式,但它完成了我的工作。

我已经使用了版本 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"

通过像这样定义依赖关系 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'
]

我使用了这些依赖项并且它工作得很好

implementation group: 'com.tinder.scarlet', name: 'scarlet', version: '0.1.10'
implementation group: 'com.tinder.scarlet', name: 'message-adapter-moshi', version: '0.1.10'

你应该使用:

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

没有猩红色前缀