Setup Kotlin for Android Studio
Since most of my articles are using code in Kotlin, I thought perhaps would be appropriate for me to introduce the simple steps for setting up Kotlin in Android Studio. Hopes this would encourage you to at least set it up if you haven’t, so that you could experiment and test whenever you like.
One great news of moving to Kotlin is, you do not need to start from a new project. Your could add it to your existing Java Android project. The language is interoperaable with Java. So you could use my steps below either for a new or existing project.
This is assuming you already have Android Studio (version 2.2 at the time of writing), its Android SDK (version 24) and Java SDK (at least 7) installed.
Step 1: Setup the Kotlin Plugin in Android Studio
In order to ensure Android Studio support Kotlin, the first thing is to install the Kotlin Plugin for your Android Studio.
Android Studio → Preferences… →Plugins → Browse Repository → type “Kotlin” in search box → install
That’s all the generically applied to your Android Studio. Only needed to do once per installation of Android Studio.
Step 2: Add Kotlin classpath to project Build.Gradle
For gradle to have Kotlin support, add the two classpaths below, i.e. Kotlin-Gradle-Plugin and Kotlin-Android-Extensions. Also in this file I setup the variable to define Kotlin version, that could be shared by all.
ext.kotlin_version = "1.1.1"
ext.supportLibVersion = "25.3.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle…