OkHttp 4 Goes Kotlin

Today’s release changes everything and nothing.

Everything?

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 .kt .

Nothing.

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 unexpected differences.

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.

Kotlin!

Kotlin’s great. It’s expressive, concise, efficient, and stable. It interops nicely with Java. Plus it gives us great options to grow.

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.

Get it

Use these new Gradle coordinates:

implementation ( "com.squareup.okhttp3:okhttp:4.0.0" )

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 upgrade.

I enjoy building stuff with Kotlin and found this upgrade particularly satisfying. Try it out and see if you agree!