All articles

How to Set Up Kotlin

This article will briefly explain how to setup Kotlin in an existing project. Kotlin is a programming language developed by JetBrains.

Kotlin is a very nice language, heavily based on Scala, it brings a lot of nice functional programming features to java.find functional programming to be particularly efficient when having to deal with the following points:

– Listeners (which is to say always on android): we have lambdas in Kotlin! (Yes yes… you have them with retrolambda, I know!)
– Lots of manipulation of collections (for instance when using adapters): high-order functions will save your life and keep your code clean!
-Using RxJava, RxA ndroid (with the binding RxKotlin): the Reactive Extensions are very useful, yes, but did you try using it with Java ? Unless you’re using retro-lambda, writing all those listeners really is ugly and makes your code unreadable!

To learn more about the cool stuff, I recommend reading the official documentation


First, you need to add the followign code at the end of your module’s build.gradle file:

buildscript {
    ext.kotlin_version = '1.+'
    repositories {
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

You can replace kotlin_version with the latest version or the version you want to use.

Then, you just need to apply the plugin, add the following line at the top of the file:

apply plugin: 'kotlin-android'

Kotlin folder

If you want to separate your .java files and your .kt files, you can create a kotlin folder in the same folder as

the java folder. If you do, you need to tell gradle where to get the additional files, to do that add the following lines to your build.gradle:

android {
    // signingConfigs {...}
    // buildTypes {...}

    sourceSets { += 'src/main/kotlin'