[英]React Native :app:checkDebugDuplicateClasses FAILED
I'm trying to implement a Trustmanager
for websocket connections in a React Native project by directly adopting the code from this gist .我正在尝试通过直接采用此 gist中的代码,在 React Native 项目中为 websocket 连接实现
Trustmanager
。 It requires the okhttp-ws
module to run.它需要
okhttp-ws
模块才能运行。
But, it fails at :app:checkDebugDuplicateClasses
但是,它在
:app:checkDebugDuplicateClasses
失败了
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
java.lang.RuntimeException: java.lang.RuntimeException:
Duplicate class okhttp3.internal.ws.RealWebSocket found in modules okhttp-3.14.1.jar (com.squareup.okhttp3:okhttp:3.14.1) and okhttp-ws-3.4.2.jar (com.squareup.okhttp3:okhttp-ws:3.4.2)
Duplicate class okhttp3.internal.ws.RealWebSocket$1 found in modules okhttp-3.14.1.jar (com.squareup.okhttp3:okhttp:3.14.1) and okhttp-ws-3.4.2.jar (com.squareup.okhttp3:okhttp-ws:3.4.2)
Duplicate class okhttp3.internal.ws.WebSocketProtocol found in modules okhttp-3.14.1.jar (com.squareup.okhttp3:okhttp:3.14.1) and okhttp-ws-3.4.2.jar (com.squareup.okhttp3:okhttp-ws:3.4.2)
Duplicate class okhttp3.internal.ws.WebSocketReader found in modules okhttp-3.14.1.jar (com.squareup.okhttp3:okhttp:3.14.1) and okhttp-ws-3.4.2.jar (com.squareup.okhttp3:okhttp-ws:3.4.2)
Duplicate class okhttp3.internal.ws.WebSocketReader$FrameCallback found in modules okhttp-3.14.1.jar (com.squareup.okhttp3:okhttp:3.14.1) and okhttp-ws-3.4.2.jar (com.squareup.okhttp3:okhttp-ws:3.4.2)
Duplicate class okhttp3.internal.ws.WebSocketWriter found in modules okhttp-3.14.1.jar (com.squareup.okhttp3:okhttp:3.14.1) and okhttp-ws-3.4.2.jar (com.squareup.okhttp3:okhttp-ws:3.4.2)
Duplicate class okhttp3.internal.ws.WebSocketWriter$FrameSink found in modules okhttp-3.14.1.jar (com.squareup.okhttp3:okhttp:3.14.1) and okhttp-ws-3.4.2.jar (com.squareup.okhttp3:okhttp-ws:3.4.2)
So, I excluded okhttp
from app/build.gradle
所以,我从
app/build.gradle
中排除了okhttp
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
// compile the ws module
implementation('com.squareup.okhttp3:okhttp-ws:+'){
// exclude the conflicting module
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
// interestingly, it's been excluded here too
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
Still, I get the same error.不过,我得到了同样的错误。 So, I visited the developer docs link that the error shows and tried searching for the Class
okhttp3.internal.ws.RealWebSocket
in Android Studio.因此,我访问了错误显示的开发人员文档链接,并尝试在 Android Studio 中搜索 Class
okhttp3.internal.ws.RealWebSocket
。 But it only shows some files from cache folder containing the troublesome Class, both of okhttp
and ws
modules, which I can't delete these files.但它只显示缓存文件夹中的一些文件,其中包含麻烦的 Class,
okhttp
和ws
模块,我无法删除这些文件。 For other classes, it just shows files from the okhttp
module only, which I can't delete either.对于其他类,它只显示来自
okhttp
模块的文件,我也无法删除。 Is there a workaround to this?有解决方法吗? What am I missing?
我错过了什么?
WebSocket is now part of the core library. WebSocket 现在是核心库的一部分。 https://square.github.io/okhttp/4.x/okhttp/okhttp3/-web-socket/
https://square.github.io/okhttp/4.x/okhttp/okhttp3/-web-socket/
So you should upgrade to 4.9.0 and stop depending on okhttp-ws, or revert to 3.12.12 (which is a supported legacy branch).所以你应该升级到 4.9.0 并停止依赖 okhttp-ws,或者恢复到 3.12.12(这是一个受支持的遗留分支)。
There is a sample here of how to use the WebSocket support in OkHttp https://github.com/square/okhttp/blob/master/samples/slack/src/main/java/okhttp3/slack/SlackApi.java There is a sample here of how to use the WebSocket support in OkHttp https://github.com/square/okhttp/blob/master/samples/slack/src/main/java/okhttp3/slack/SlackApi.java
Or use the built in react-native support https://reactnative.dev/docs/network或者使用内置的 react-native 支持https://reactnative.dev/docs/network
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.