English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Kotlin Android Environment Setup

Kotlin is a statically typed programming language that runs on the Java Virtual Machine, known as the Swift of the Android world, designed and developed by JetBrains and open sourced.

Kotlin can be compiled into Java bytecode and can also be compiled into JavaScript, which is convenient for running on devices without JVM.

At Google I/O 2017Google announced Kotlin as the official development language for Android.

Install Kotlin plugin

Android Studio from 3Starting from version .0, Android Studio will integrate the installation of the Kotlin plugin.

Open Settings in Android Studio, select Plugins option, click Browse Repositories, search for Kotlin in the opened window, and clickInstall. As shown in the figure:

 

 I have installed it, so there is noInstallicon, which is not installed will have, click to install

After downloading and installing, it will prompt you to restart Android Studio, and after restarting, you can use it.

 Of course, you still need to configure it in Android Studio

Configure the corresponding parameters under build.gradle in your Project and under moudle build.gradle.
Parameters in build.gradle under project

Parameters in build.gradle under module

 

You can configure to create Kotlin files after configuration, of course, you can also create Kotlin files directly, but it will display “Kotlin not configured”, click “Configure”, and enter the Kotlin configuration page.

Select the version, ok, and the automatic generation of the manual configuration information above is generated.

Java code converted to Kotlin code

The default when creating a project is like this

 Conversion: Click Code in the top navigation bar of Android Studio development tool--> Convert Java File to Kotlin File  After conversion, you can see the activity written in Kotlin.

As shown in the figure above, it is completed.