Android:okhttp3>崩溃:意外的TLS版本:无

时间:2017-12-12 06:01:41

标签: android retrofit2 okhttp3

几个月前我已整合retrofit2;直到昨天与用户(华为,型号MHA-L29,在Android 7.0上)没有问题:

Fatal Exception: java.lang.IllegalArgumentException: Unexpected TLS version: NONE
       at okhttp3.TlsVersion.forJavaName(TlsVersion.java:53)
       at okhttp3.Handshake.get(Handshake.java:56)
       at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:300)
       at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:268)
       at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:160)
       at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:256)
       at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)
       at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)
       at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
       at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
       at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
       at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
       at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
       at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at java.lang.Thread.run(Thread.java:776)

在我的Gradle

  

实施'com.squareup.retrofit2:改造:2.3.0'

你有关于此次崩溃的一些想法吗?是否有Retrofit的链接?我没有在OkHttp library中添加Gradle,我必须这样做吗?

2 个答案:

答案 0 :(得分:0)

你可以通过提供TLS配置来尝试这个吗我不确定这是否有效。从here

引用
ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
        .tlsVersions(TlsVersion.TLS_1_2)
        .cipherSuites(
                CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
                CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
                CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256)
        .build();

OkHttpClient client = new OkHttpClient.Builder()
        .connectionSpecs(Collections.singletonList(spec))
        .build();

Retrofit retrofit = new Retrofit.Builder()
        .baseUrl(BASE_URL)
        .client(client)
        .build();

答案 1 :(得分:0)

我认为此错误是3.11.0版本的结果。您可以在此处查看有关此问题的答案:Android: okhttp3 > crash: Unexpected TLS version: NONE