Certain TLS features like Server Name Indication (SNI) and Application-Layer Protocol Negotiation (ALPN) existed in Android before they had public APIs. The code was there; there just wasn’t a good way to use it.
OkHttp hacks around such limitations with reflection. Our internal platform package integrates both Android and JVM-specific features to get the best behavior even when public APIs don’t exist. When public APIs eventually get published we update OkHttp to use them. We don’t want to use more reflection than strictly necessary!
With Android 11 Google is restricting some old APIs that OkHttp was using. If you use an old OkHttp release to target Android API 30, you’ll get this weird crash:
IllegalStateException: Expected Android API level 21+ but was 29 at okhttp3.internal.platform.AndroidPlatform.buildIfSupported at okhttp3.internal.platform.Platform.findPlatform
The best fix is to use the latest OkHttp, which is 4.4.0 as of this post.
UPDATE 2020-03-01: We introduced a regression on 3.12.9 and you’ll need 3.12.10 to work on releases earlier than 4.4.