Program type already present: okhttp3.internal.ws.RealWebSocket$1.class
在原本的代码中已经使用了OKHTTP和rxjava,然后今天依赖retrofit的时候一直报错
Program type already present: okhttp3.internal.ws.RealWebSocket$1.class
说是我重复添加了OKHTTP的包,但其实我直接把OKHTTP的依赖注释掉都没用,只要依赖retrofit相关的就一定报这个错
网上推荐添加以下配置,但我尝试后无效,你们可以试试
configurations.all { // OkHttp 3.5.0+ includes the websockets API, so we need this to prevent a conflict exclude module: 'okhttp-ws' }
最后我在这里https://github.com/facebook/react-native/issues/12646找到一个答案,catch成功
解决方法如下:
因为是okhttp3.5.0之后的版本才加入的okhttp-ws,所以把版本强制控制在3.5.0以下:
configurations.all { resolutionStrategy.force 'com.squareup.okhttp3:okhttp:3.4.1' }
重新build,代码不再报错