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

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


For minSDK lower than 21, change your OkHttp version to 3.12.12 in gradle like this -

  //OkHttp  implementation ("com.squareup.okhttp3:okhttp:3.12.12"){      force = true //API 19 support  }  implementation 'com.squareup.okhttp3:logging-interceptor:3.12.12'

It should work fine!


OKHTTP just dropped support for Android 4

https://github.com/square/okhttp/issues/4481

You must use an older version or maybe a sperate branch for your app.

See this Medium post from Jessie Wilson for more info:https://medium.com/square-corner-blog/okhttp-3-13-requires-android-5-818bb78d07ce


For everyone who still need the library for older version of Android, you need to use the OkHttp 3.12.x branch. The latest release from the branch is 3.12.6. I've tested and confirmed the version worked on Samsung Tablet SM-T116NU (Android 19).

Here's the excerpt from OkHttp:

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 through December 31, 2020.