在Android 4.4.4上改进SSL错误

时间:2014-08-27 23:18:53

标签: android retrofit

我们有一个现有的Android应用程序,它使用Retrofit连接到服务器并发送和接收JSON。自从我的设备更新到Android 4.4.4后,我在尝试连接时遇到以下错误:

D/Retrofit(8004): javax.net.ssl.SSLException: Read error: ssl=0x768c5c40: I/O error during system call, Connection reset by peer
D/Retrofit(8004):  at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
D/Retrofit(8004):  at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:689)
D/Retrofit(8004):  at okio.Okio$2.read(Okio.java:136)
D/Retrofit(8004):  at okio.AsyncTimeout$2.read(AsyncTimeout.java:211)
D/Retrofit(8004):  at okio.RealBufferedSource.indexOf(RealBufferedSource.java:244)
D/Retrofit(8004):  at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:191)
D/Retrofit(8004):  at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:189)
D/Retrofit(8004):  at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:101)
D/Retrofit(8004):  at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:676)
D/Retrofit(8004):  at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:426)
D/Retrofit(8004):  at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:371)
D/Retrofit(8004):  at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:466)
D/Retrofit(8004):  at com.squareup.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105)
D/Retrofit(8004):  at com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:25)
D/Retrofit(8004):  at retrofit.client.UrlConnectionClient.readResponse(UrlConnectionClient.java:73)
D/Retrofit(8004):  at retrofit.client.UrlConnectionClient.execute(UrlConnectionClient.java:38)
D/Retrofit(8004):  at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:321)
D/Retrofit(8004):  at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
D/Retrofit(8004):  at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
D/Retrofit(8004):  at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
D/Retrofit(8004):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
D/Retrofit(8004):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
D/Retrofit(8004):  at retrofit.Platform$Android$2$1.run(Platform.java:142)
D/Retrofit(8004):  at java.lang.Thread.run(Thread.java:841)

我已更新到最新版本的Retrofit / OkHTTP和Okio,但错误仍然存​​在。我猜测这与Android 4.4.4中的OpenSSL补丁有关,但我无法找到解决此错误的方法。

是否还有其他人遇到此问题,如果有的话,找到了修复方法?

由于

1 个答案:

答案 0 :(得分:0)

要在 Pre-lollipop Android 中使用 Retrofit,您应该使用较低版本的 OKhttp 并强制实现支持 Pre-lollipop 的特定版本

implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation ("com.squareup.okhttp3:okhttp:3.12.12"){
    force = true //API 19 support
}