Chapter 1 : Configuring Android Studio with Kotlin

In previous article, we knew that Kotlin is more powerful language and you should try it and that’s the reason why you are here. In this article, we will learn how you can configure Android studio with Kotlin.

Start Android Studio, and create new project as below.

Android Studio 3.0

New projec + Kotlin support
New projec + Kotlin support

Finish the flow to create project and wait till build process complete.

For Android Studio 2.x version, you require to install plugin. You can do it by File -> Settings -> Plugin and search for “Kotlin”. Install it and restart your Android Studio.

Let’s first look at project level “gradle” file.

project level build.gradle
project level build.gradle

1) Kotlin dependency version declare. (While writing this, version is 1.1.3-2)
2) Kotlin dependency plug-in declared

Now take a lookk at module level “gradle” file.

module level build.gradle
module level build.gradle

1) Plug-ins are applied to module
2) Kotlin standard library. You can know more about it at kotlinlang.org

If you notice, when Kotlin class is created, its by default extension will be “.kt”.

MainActivity.kt
MainActivity.kt

1) Any implementation will be here with : (colon) and class default constructor sign.
2) Any overrided method starts with override keyword.
3) You need to write : after object and ? after class to declare object.

Now, run your application.

HelloKotlin output
HelloKotlin output

Protected by Copyscape

Share on Facebook18Share on Google+20Tweet about this on TwitterShare on LinkedIn0Share on Reddit0Pin on Pinterest0Share on Tumblr0Email this to someone