Today I’m starting a set of 30 articles about Kotlin for Android Developers (KAD). In these articles I’ll be talking about the most important parts of the language and how they apply to Android development.

From the very beginning, so if you’ve heard about Kotlin but never tried, then this articles are perfect for you. ¡Hope you enjoy them!

In today’s article, I want to show you how easy is to create an Kotlin project from scratch.

Creating an Android project for Kotlin from scratch

First thing you need is to download the latest stable version of Android Studio. Canary or Beta should be OK, but new versions sometimes break the Kotlin plugin for some days.

Once done, install the Kotlin plugin. IntelliJ comes with it already installed by default, but it’s not the same for Android Studio.

1. Install Kotlin plugin

In order to do this, go to Plugins section in “Preferences”, and use the search bar to find it:

Plugin Kotlin Android Studio

2. Create a new Android project

Now that you’ve installed your plugin (you can even do it later if you want), create an Android Project.

Nothing different from a regular project:

proyecto-kotlin-android

Choose “Blank Screen” among the “New Activity” options. It will be easier to convert the code later.

3. Convert the new Activity to Kotlin code

You just need to select a menu option. Literally.

The Kotlin plugin includes a conversor from Java to Kotlin code (not the other way round, but you won’t want it anyway 😝). Just open the class you want to convert and chos the option Code -> Convert Java File to Kotlin File.

And that’s all. This is the result of the operation:

As you can see, though there are some similarities with Java code, there are many other differences. You’ll learn some of them in next articles.

4. Convert the project to a Kotlin project

Another utility of the plugin will do this for you. Just go to Tools -> Kotlin -> Configure Kotlin in Project, and use the dialog to add some changes to build.gradle files:

dialogo-configuracion-kotlin-android

What did this change? A new dependency to the Kotlin plugin was added in the root build.gradle:

It also applied the Kotlin plugin to the module build.gradle:

And added the Kotlin library as a dependency:

Conclusion

And that’s all! You can now run the project and see how it perfectly works.

The compilation will take a little more than Java the first time and, according to this article, incremental builds would be even faster than Java.

Cool, right? Let me know what you think in the comments section.

Author: Antonio Leiva

I’m in love with Kotlin. I’ve been learning about it for a couple of years, applying it to Android and digesting all this knowledge so that you can learn it with no effort.