Cash App Jun 26, 2019

OkHttp 4 Goes Kotlin

Article Summary

Jesse Wilson from Square just rewrote 25,000 lines of Java code in Kotlin without changing a single feature or fixing a single bug. Here's why that matters for your Android app.

OkHttp, one of the most widely used HTTP clients for Android and Java, released version 4.0 with its entire codebase converted from Java to Kotlin. Square's team prioritized maintaining complete compatibility while modernizing their foundation for future growth.

Key Takeaways

Critical Insight

OkHttp 4.0 proves you can modernize a massive codebase to Kotlin while maintaining perfect backward compatibility for Java users.

The upgrade guide reveals specific gotchas with ProGuard and Mockito that could save you hours of debugging.

About This Article

Problem

Square needed to update OkHttp's foundation while keeping it stable and compatible for the millions of Java developers using it.

Solution

Jesse Wilson's team used japicmp to check that binary compatibility stayed intact and ran the same test suite throughout the Kotlin migration to catch any unexpected changes.

Impact

OkHttp 4.0 added a 1.2 MiB Kotlin stdlib dependency that gets much smaller when you use ProGuard or R8 optimization, so the library can grow without breaking existing Java applications.