OkHttp 4 Goes Kotlin
Today’s release changes everything and nothing.
OkHttp is an HTTP client for Java and Android. Until today the library itself was all
Java. With version 4 we’ve switched to Kotlin, replacing 25K lines of
.java with equivalent
We haven’t changed the package name (still
okhttp3, welp), the APIs, or the performance. We
haven’t added features or even fixed any bugs! We’ll get back to that in 4.1.
The new release is binary and Java-source compatible. Swap in our new
.jar and your program will
work the same as it always has. It retains the same minimum requirements of Android 5+ and Java 8+.
We enforce binary compatibility using japicmp and left our test suite unchanged to detect
The biggest impact you’ll see is a new dependency on the Kotlin standard library. It adds about 1.2 MiB, or much less with ProGuard or R8.
If you’re already using OkHttp with Kotlin, this upgrade breaks source compatibility. We’ve changed Kotlin-facing APIs to use Kotlin idioms. Our upgrade guide shows how to do a fast and safe migration.
Use these new Gradle coordinates:
Please read the upgrade guide, especially if you’re using ProGuard or
Mockito. If you’re using other libraries in the
com.squareup.okhttp3 group, they all
need the same version. This includes MockWebServer, which is included in our Kotlin
I enjoy building stuff with Kotlin and found this upgrade particularly satisfying. Try it out and see if you agree!