How to use, configure, install Kotlin in Android Studio

Hello viewer, You can now have our Tutorial Lessons in your android mobile device and read it offline.
Download kotlin Programming APP on PlayStore
Download Website SEO Lessons APP on PlayStore

What are the advantages of using Kotlin to develop your application?

Functional programming and object-oriented programming

Inference of types (as in Javascript, one can write: val foo = “bar”).

– More than NullPointerException .
– Overload of operators . C ++ developers already know the full potential of this feature.
– Javadoc in Markdown .

– Syntax more concise (shorter declarations, no accessors, no semicolon at the end of the line).

– Compatible with Java, (as with Groovy): migration is facilitated.

– Conversion Java to Kotlin possible and assisted (almost automatic in IntelliJ).

If you are already on Android Studio 3.0 you do not have to add Kotlin because it is directly integrated. However, for the other versions, installation of the Kotlin plugin will be necessary.

Topic: How to use, configure, install Kotlin in Android Studio.

2 – How to install the Kotlin plugin in Android Studio?

Go to the menu: File | Settings | Plugins | Install JetBrains plugin … then search “Kotlin” and install it. If you are on the ” Welcome to Android Studio ” homepage, choose Configure | Plugins | Install JetBrains plugin … it will be necessary to restart Android Studio to complete the installation.

How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio

Now create a new project and follow the creation process by specifying the necessary information (project name, package name, company domain etc).

Topic: How to use, configure, install Kotlin in Android Studio.

 

How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio

 

For Android Studio 3.0, it already has an option to I include Kotlin support as shown in the capture below . Android Studio will do all the work for you and download the Kotlin plugin and dependencies of your project, not necessary to follow the other steps just launch your application!

Topic: How to use, configure, install Kotlin in Android Studio.

 

How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio

 

Choose Android version:

 

How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio

 

Choose an activity to generate. By default we will choose an “Empty Activity”.

How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio

Now you’re almost finished, name the activity:

How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio

3 – How to convert Java code to Kotlin:

Open your activity which is MainActivity.java here, you need to use an IntelliJ action. Press the Ctrl + Shift + A keys and type the following action:

 

How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio

 

You should see a file with a .kt extension instead of .java now.

Topic: How to use, configure, install Kotlin in Android Studio.

package com.nagarro.newapp

import android.support.v7.app.AppCompatActivity
import android.os.Bundle

class MainActivity : AppCompatActivity() {
//coding180.com
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
  }
}

Good! Everything is fine. Just one last step, you need to configure Kotlin. If you build an application and run it on the emulator or try to edit this file, Android Studio will tell you that Kotlin is not configured, so you need to configure it.

How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio

A window appears and you can choose the Kotlin compiler and the runtime version. Choose the most recent version in the list:

 

How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio

 

You should find in module and build.gradle file. It added the line apply plugin: ‘kotlin-android’ and added compile dependencies “org.jetbrains.kotlin: kotlin-stdlib-jre7: $ kotlin_version”

 

How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio

 

Let’s look at the changes made in the build.gradle file:

How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio

Perfect ! You succeeded !! Synchronize the project

How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio - How to use, configure, install Kotlin in Android Studio

About The Author

Related posts

Leave a Reply