How to fix Expected Android API level 21+ but was 19 in Android

后端 未结 11 1751
甜味超标
甜味超标 2020-12-10 01:06

In my application i want get data from server, for get connect to server i used Retrofit, OkHttp.
But when running application, show me

11条回答
  •  离开以前
    2020-12-10 01:52

    According to Okhttp documentation, they dropped the support for Android 4.

    The solution is to use the 3.12.x versions of Okhttp:

    def okhttp_version="3.12.0"
    implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"
    implementation("com.squareup.okhttp3:okhttp") {
        version { strictly "$okhttp_version" }
    }
    

    You can also read about the reason for this change in Square blog:

    Why Android 5+ and Why Now?

    TLS is the mechanism that makes HTTPS calls secure, private, and authenticated. OkHttp is aware of five versions: SSLv3 (1996), TLSv1 (1999), TLSv1.1 (2006), TLSv1.2 (2008), and TLSv1.3 (2018). We dropped support for SSLv3 in 2014 in response to the POODLE attack.

    Now it’s time to drop both TLSv1 and TLSv1.1 and to make TLSv1.2 the Internet’s new minimum standard. On October 15 our colleagues at Google, Mozilla, Microsoft, and Apple announced that their browsers will require TLSv1.2 or better starting in early 2020.

    Google added support for TLSv1.2 in Android 5.0. Oracle added it in Java 8. In OkHttp 3.13 we require that the host platform has built-in support for TLSv1.2.

    What about Android 4.x?

    Google’s distribution dashboard shows that ~11% of the devices that visited the Play Store in October 2018 were running Android 4.x. We’ve created a branch, OkHttp 3.12.x, to support these devices. Should we encounter any severe bugs or security problems we’ll backport the fixes and release. We plan to maintain this branch through December 31, 2020.

    If you really need TLSv1.2 on Android 4.x, that’s possible! Ankush Gupta has written a thorough guide that explains how to get Google Play Services to do it. Even if you follow this process you should still use OkHttp 3.12.x with Android 4.x devices.

提交回复
热议问题