Announcing Okio 2: Our fast + simple I/O library, Okio, has a new release that supports Kotlin.

Jesse Wilson
Aug 27, 2018 · 3 min read
Image for post
Image for post

Heads up, we’ve moved! If you’d like to continue keeping up with the latest technical content from Square please visit us at our new home https://developer.squareup.com/blog

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

Image for post
Image for post
IntelliJ makes fixing deprecations easy

Dependencies

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

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.

Square Corner Blog

Buying and selling sound like simple things - and they…

Thanks to Jake Wharton

Jesse Wilson

Written by

Android and jokes.

Square Corner Blog

Buying and selling sound like simple things - and they should be. Somewhere along the way, they got complicated. At Square, we're working hard to make commerce easy for everyone.

Jesse Wilson

Written by

Android and jokes.

Square Corner Blog

Buying and selling sound like simple things - and they should be. Somewhere along the way, they got complicated. At Square, we're working hard to make commerce easy for everyone.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store