Converting a TODO app to Kotlin (part 1 - Intro)

I first heard about Kotlin from a document written by Jake Wharton about using Kotlin for Android development. I was intrigued by the language and I watched a few conference talks about it. I liked what I saw but due to various reasons I didn’t start playing with the language right away.

Kotlin Logo

In September a decided to give Kotlin a shot. I started with completing the Kotlin Koans on-line on It’s a series of 42 exercises, created as a failing unit test, designed to get you familiar with the Koltin syntax and features. They are also available on Github.

The next step for me is trying it in an Android app. Kotlin is interoperable with Java, you can call Java code from Kotlin and you can call Kotlin code from Java. This is very useful because I can take an existing project and convert it to Kotlin one class/file at a time. The Kotlin plug-in has a tool that does this.

Engineers from Google, together with the community, maintain the Android Architecture Blueprints project. It demonstrates different architectures for building a TO-DO application for Android. From the project README:

The aim of the app is to be simple enough that it’s understood quickly, but complex enough to showcase difficult design decisions and testing scenarios.

What if instead of comparing different architectures I compare different languages. Android Architecture Blueprints

I forked the project to my Github account and I’ll post the code there. I will use the todo-mvp branch as a base for my conversion.

The first step is to configure Kotlin in the project. Assuming the Kotlin Plugin is installed this step is accomplished with a single command: Configure Kotlin in project (Tools -> Kotlin -> Configure Kotlin in Project). The command adds the kotlin gradle plugin to the classpath (in the top level build.gradle file), applies the kotlin-android plugin, adds src/main/kotlin to the source sets and adds the kotlin standard library as a dependency. You can read more about setting up Kotlin with gradle in the official documentation. The commit with the changes is here.

In the next article I’ll convert some Java code to Kotlin starting with the model layer (data package).

If you enjoyed the article you might enjoy following me on twitter

comments powered by Disqus