简体   繁体   English

React Native:app:checkDebugDuplicateClasses 失败

[英]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, okhttpws模块,我无法删除这些文件。 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.

相关问题 任务 ':app:checkDebugDuplicateClasses' 执行失败。 反应原生 - Execution failed for task ':app:checkDebugDuplicateClasses'. React Native 反应本机构建失败任务':app:checkDebugDuplicateClasses'的执行失败 - React native build failed Execution failed for task ':app:checkDebugDuplicateClasses' 构建失败 - 任务:应用程序:checkDebugDuplicateClasses FAILED - Build Failed - Task :app:checkDebugDuplicateClasses FAILED flutter 和 android gradle 错误:任务 ':app:checkDebugDuplicateClasses' 执行失败 - error with flutter and android gradle :Execution failed for task ':app:checkDebugDuplicateClasses' 任务 ':app:checkDebugDuplicateClasses' 执行失败,使用 -Xlint:deprecation 重新编译以获取详细信息 - Execution failed for task ':app:checkDebugDuplicateClasses', Recompile with -Xlint:deprecation for details Android 构建错误任务':app:checkDebugDuplicateClasses'的执行失败 - Android build error Execution failed for task ':app:checkDebugDuplicateClasses' 任务“:app:checkDebugDuplicateClasses”执行失败。 在 Android Studio 4.2.2 上 - Execution failed for task ':app:checkDebugDuplicateClasses'. on Android studio 4.2.2 任务 ':app:checkDebugDuplicateClasses' 执行失败。 离子4 Android - Execution failed for task ':app:checkDebugDuplicateClasses'. Ionic4 Android 反应原生:app:transformClassesWithDexForDebug失败 - React native :app:transformClassesWithDexForDebug FAILED React Native:app:validateSigningRelease FAILED - React Native :app:validateSigningRelease FAILED
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM