Getting started with Kotlin on Android

Kotlin is fully supported in Android Studio 3.0, so it’s easy to create new projects with Kotlin files, add Kotlin files to your existing project, and convert Java language code to Kotlin.

You can then use of all Android Studio’s existing tools with your Kotlin code, such as autocomplete, lint checker, refactoring, debugging, and more.

Create a new project with Kotlin

Using Kotlin with a new project requires just one extra click in the New Project wizard:

  1. In Android Studio, click File > New > New Project. Or if you’ve just opened Android Studio and see the Welcome to Android Studio window, click Start a new Android Studio project.
  2. On the first screen, check Include Kotlin support. That’s the only difference.
  3. Click Next and continue through the wizard until you’re done.

Android Studio 3.0 offers an option to enable Kotlin support on this screen. You can check this option and skip the “Configuring Kotlin in the project” step below.

Choose the Android version:

If you are planning to test the app on your phone, make sure the minimum SDK is below your phone’s operating system level.

Choose creating an activity that will be generated for you:

Leave all of the Activity name fields as they are.

In Android Studio 3.0, you can choose to create the activity in Kotlin right away, so you can skip the “Converting Java code to Kotlin” step. Earlier versions will create an activity in Java, and you can use the automated converter tool to convert it.

MainActivity.kt

 Output :-

About Jaimin Patel

I am a Web Developer. I have been blogging and researching since 1 years and like to share my knowledge and research with the world. Peace..!!

View all posts by Jaimin Patel →

Leave a Reply

Your email address will not be published. Required fields are marked *