今天在请求网络的时候遇到了如下问题
java.io.IOException: canceled due to java.lang.NoSuchMethodError: No virtual method log(ILjava/lang/String;Ljava/lang/Throwable;)V in class Lokhttp3/internal/platform/Platform; or its super classes (declaration of 'okhttp3.internal.platform.Platform' appears in /data/app/~~CTMez4oVeQIukZV-KAfXnQ==/com.autoai.media.center-3E_sT_w19P965eO8b8fphw==/base.apk!classes4.dex)
我的网络请求放到共通模块下了,但是奇怪的是我其他模块的网络请求是好用的 ,就说明共通模块没问题,后来调查发现是因为目前的模块引入了一个三方的sdk,我的okhttp的版本和他们冲突了,他们用的是com.squareup.okhttp3:okhttp:4.10.0我用的是com.squareup.okhttp3:okhttp:3.12.0,这就导致了编译时使用的库和运行时使用的库版本不匹配。然后我在当前的模块下加入下面的代码,问题解决!
implementation com.squareup.okhttp3:okhttp:4.10.0
implementation com.squareup.okhttp3:logging-interceptor:4.10.0
configurations.configureEach {
resolutionStrategy.force com.squareup.okhttp3:okhttp:4.10.0
resolutionStrategy.force com.squareup.okhttp3:logging-interceptor:4.10.0
}