Learn2Crack

Getting Started with Android Development in Kotlin

Kotlin is a modern and powerful language which overcomes many disadvantages of Java. It runs on Java Virtual Machine (JVM). It is interoperable with Java, so your existing Java libraries work well with Kotlin. It is developed by JetBrains which is the company behind IntelliJ Idea. As announced in last Google I/O Kotlin is an officially supported language for Android Development. Android Studio 3.0 had a stable release few weeks back which includes all the necessary tools and plugins required for Kotlin. In this tutorial lets discuss some of the basics.

Prerequisites

If you are absolute beginner to Kotlin, the official Kotlin docs are the best place to start,

Android Studio

Android Studio 3.0 was released a few weeks back which includes complete support for Kotlin. Make sure you update Android Studio to version 3.0

Android Virtual Device

You can create a new Android Virtual Device (AVD) in order to test your app on your PC. Android Virtual Device Manager now allows you to download a Virtual Device with built-in Google Play Store support and an easier way to update Google Play Services.

Creating New Project

It is same as we done before. Don’t forget to check Include Kotlin support option which takes care of everything.

All the Kotlin files will have the extension kt.

Gradle File

Let’s take a look at the root build.gradle and app’s build.gradle file. The root build.gradle has Kotlin Gradle plugin added to dependencies. Since Android Studio 3.0 comes inbuilt with kotlin plugin these dependencies get added automatically on creating a new project.

Now let’s take a look at app build.gradle file. You can see kotlin-android and kotlin-android-extensions plugin is added. This kotlin-android-extensions plugin will help to replace findViewById() method in Views and it makes simpler.

Activity

Here you can see a String is set as text to TextView by using textView.text property. No findViewById(), simple isn’t it ? This is possible via the Kotlin Android Extensions. You can just access the View via the Id you defined in the layout.