Announcing Okio 2
Our I/O library is converting to Kotlin.
At Square, we’re excited about Kotlin. It’s a capable language to build Java libraries and applications with. We love to write code that is both compact and efficient.
We’re also eager to adopt Kotlin’s powerful new features. Kotlin/Native will allow us to share code between iOS and Android. Coroutines make concurrent programs easier to create and maintain.
Today we’re releasing Okio 2.0. In this release we’ve converted the project’s source code from .java
to .kt
. The conversion lets us use Kotlin in the library and offer APIs that feel right when the calling code is in Kotlin. It also gives us the opportunity to support multiplatform and coroutines in the future.
Compatibility
The new release is binary-compatible with Okio 1.15.0. You can replace the old .jar
file with the new one and your applications and libraries should just work.
The update is also Java source-compatible. When you configure your pom.xml
or build.gradle
to use the new version you won’t have to change any .java
code to get a clean build. (Our changelog notes one minor exception to this, unrelated to the Kotlin transition.)
But the update is not Kotlin source-compatible; it adopts Kotlin idioms where they apply. For example, if you’re using ByteString.decodeHex("f00d")
you’ll now need "f00d".decodeHex()
. We’re using Kotlin’s @Deprecated
annotation for a smooth upgrade process.
IntelliJ makes fixing deprecations easy
Dependencies
Okio is core to many of Square’s open source projects. We use it for fast I/O in OkHttp, Retrofit, Moshi, and Wire. When these projects upgrade to Okio 2 they will gain a transitive dependency on Kotlin’s standard library.
Kotlin is the best language for Android application development. We expect many Android teams to already be using Kotlin. For their projects Kotlin is already among the applications’ dependencies. Those that don’t can use R8 or ProGuard to shrink the Kotlin library dependency. When we measured the net increase was negligible: just 7 KiB.
For server applications we expect the dependency size to be inconsequential. But we worry about potential diamond-dependency versioning problems. To minimize the chance of such problems we will avoid experimental and deprecated APIs.
For libraries and SDKs that use Okio or its sibling libraries we assume the ultimate deployment target will be to Android or a server. In either case we believe the dependency is acceptable.
Good Stuff
Kotlin is a beautiful language with broad applications. We hope Okio 2 helps to further extend Kotlin’s capabilities.
Get the new Okio with Gradle:
compile ‘com.squareup.okio:okio:2.0.0’
Or Maven:
<dependency>
<groupId>com.squareup.okio</groupId>
<artifactId>okio</artifactId>
<version>2.0.0</version>
</dependency>
Full release details are in the changelog. The readme has an API guide.