通過這個我們知道了okhttp3 從3.13.0之后不再支持android5.0以下的系統(tǒng)了。
如果你用了implementation("com.squareup.okhttp3:okhttp:latest.release")就會出現(xiàn)
ANDROID項目使用OKHTTP3的時候報錯STATIC INTERFACE METHODS ARE ONLY SUPPORTED STARTING WITH ANDROID N
一個老的項目在引入OkHttp3最新版本3.13.1之后編譯報錯,信息如下
AGPBI: {“kind”:”error”,”text”:”Static interface methods are only supported starting with Android N (–min-api 24): okhttp3.Request okhttp3.Authenticator.lambda$static$0(okhttp3.Route, okhttp3.Response)”,”sources”:[{}],”tool”:”D8”}
去OkHttp官方看了一下3.13.1的release note,有一段信息如下
我們通過okhttp(github)網(wǎng)站上看到了這么一段話
OkHttp works on Android 5.0+ (API level 21+) and on Java 8+.
OkHttp has one library dependency on [Okio](https://github.com/square/okio/), a small library for high-performance I/O. It works with either Okio 1.x (implemented in Java) or Okio 2.x (upgraded to Kotlin).
We highly recommend you keep OkHttp up-to-date. As with auto-updating web browsers, staying current with HTTPS clients is an important defense against potential security problems. [We track](https://github.com/square/okhttp/wiki/TLS-Configuration-History) the dynamic TLS ecosystem and adjust OkHttp to improve connectivity and security.
OkHttp uses your platform's built-in TLS implementation. On Java platforms OkHttp also supports [Conscrypt](https://github.com/google/conscrypt/), which integrates BoringSSL with Java. OkHttp will use Conscrypt if it is the first security provider:
Security.insertProviderAt(Conscrypt.newProvider(), 1);
The OkHttp 3.12.x branch supports Android 2.3+ (API level 9+) and Java 7+. These platforms lack support for TLS 1.2 and should not be used. But because upgrading is difficult we will backport critical fixes to the [3.12.x branch](https://github.com/square/okhttp/tree/okhttp_3.12.x) through December 31, 2020.
翻譯:
OkHttp工作在Android 5 +(API級別21 +)和Java 8 +上。
OkHttp有一個庫依賴于[Oki](http://Github.com/方/ Oki/),它是一個用于高性能I/O的小庫,它與Okio 1 .x(Java實現(xiàn))或OKIO 2。x(升級到Kotlin)一起工作。
我們強烈建議您保持OKHTTP最新。與自動更新Web瀏覽器一樣,保持HTTPS客戶端的最新狀態(tài)是防止?jié)撛诎踩珕栴}的重要防御措施。[我們跟蹤](https://github.com/square/okhttp/wiki/tls配置歷史)動態(tài)TLS生態(tài)系統(tǒng)并調(diào)整okhttp以提高連接性和安全性。
OKHTTP使用平臺的內(nèi)置TLS實現(xiàn)。在Java平臺上,OKHTTP還支持了[CONSCRYPT](http://Github.com/谷歌/CONSCRYPT),它集成了BRIGIN SSL和Java。如果是第一個安全提供者,OKHTTP將使用Conscrypt:
security.insertProviderAt(conscrypt.newProvider(),1);
OKHTTP 3.12 .x分支支持Android 2.3 +(API級別9 +)和Java 7 +。這些平臺不支持TLS 1.2,因此不應(yīng)使用。但是因為升級很困難,我們將把關(guān)鍵的修復(fù)移植到[3.12.x分支(https://github.com/square/okhttp/tree/okhttp_3.12.x)到2020年12月31日。
3.13.x 這個版本最低版本需要Java8+和Android 5+支持,如果你需要兼容老設(shè)備,用之前的版本就行了,如果只是想編譯通過,可以在gradle文件里面添加下面配置信息
compileOptions {
targetCompatibility = "8"
sourceCompatibility = "8"
}