How to Setup Kotlin Plugin in Android Studio Tutorial

Kotlin is a programming language launched by JetBrains, the official designer of essentially the most intelligent Java IDE, named Intellij IDEA.

Don't Miss

One nice information of shifting to Kotlin is, you don’t want to begin from a new project. Your may add it to your present Java Android project. The language is interoperaable with Java. So you would use my steps below both for a new or present project.

In this tutorial, we are installing kotlin in android studio.

Here, we are explaining, how to convert existing Android project to Kotlin ( Convert java to kotlin) & Also explaining how to create new project in Kotlin for beginners

Prerequisite

This is assuming you have already got Android Studio (version 2.2 on the time of writing), its Android SDK (version 24) and Java SDK (not less than 7) installed.

Add Kotlin Plugin in Android Studio

In order to make sure Android Studio support Kotlin, the very first thing is to install the Kotlin Plugin in your Android Studio.

  • Open Your Android Studio
  • Go to File => Settings => Plugins => type “Kotlin” in search box => install
kotlin-min

Add Kotlin classpath to project Build.Gradle

To Kotlin assist within the gradle, add the 2 classpaths below, i.e. Kotlin-Gradle-Plugin and Kotlin-Android-Extensions. Also on this file I setup the variable to define Kotlin version, that may very well be shared by all. Follow the below code:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.72'
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Add Kotlin Dependency and apply Kotlin Plugins in app module Build.gradle.

In the module that may use Kotlin, you’ll add the Kotlin library into it’s Build.gradle. Also keep in mind to use both the Kotlin Android and it’s extension plugin to your project (I usually forgot this, after add the library).

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
 compileSdkVersion 29
buildToolsVersion "29.0.3"

 defaultConfig {
 applicationId "in.studytutorial.myapplication"
 minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"

 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
 }

 buildTypes {
 release {
 minifyEnabled false
 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
 }
 }

}

dependencies {
 implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
 implementation 'androidx.appcompat:appcompat:1.1.0'
 implementation 'androidx.core:core-ktx:1.2.0'
 implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
 testImplementation 'junit:junit:4.12'
 androidTestImplementation 'androidx.test.ext:junit:1.1.1'
 androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

Synchronize & Convert Code

Now you’ve setup Kotlin in your app improvement, you would begin writing Kotlin code (in .kt extension). Another way is convert your Java file to Kotlin, using Shift-Alt-Ctrl-K  Convert Java File to Kotlin File.

New Project In Kotlin

If we’re creating new project in kotlin the Open Android Studio => FIle => New => New Project => Choose your template => Change language to Kotlin while Configure your project => Finish.

It will automatically build in Kotlin Language project.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

564FansLike

Recent Posts

Concept of Session in Laravel Tutorial

Sessions are used to store details about the user throughout the requests. Laravel supplies various drivers like file, cookie, apc, array, Memcached, Redis, and database to handle session data. By default, file driver is used as a result of it's light-weight....

Laravel Url Generation Tutorial

Our web application revolves around routes and URLs. After all, they're what direct our users to our pages. At the end of the day, serving pages is what any web application should do. Our users may...

Concept of Laravel Views Tutorial

In MVC framework, the letter "V" stands for Views. It separates the application logic and presentation logic. Views are saved in resources/views listing. Generally, the view contains the HTML which might be served by the application.

Related Articles

Concept of Session in Laravel Tutorial

Sessions are used to store details about the user throughout the requests. Laravel supplies various drivers like file, cookie, apc, array, Memcached, Redis, and database to handle session data. By default, file driver is used as a result of it's light-weight....

Laravel Url Generation Tutorial

Our web application revolves around routes and URLs. After all, they're what direct our users to our pages. At the end of the day, serving pages is what any web application should do. Our users may...

Concept of Laravel Views Tutorial

In MVC framework, the letter "V" stands for Views. It separates the application logic and presentation logic. Views are saved in resources/views listing. Generally, the view contains the HTML which might be served by the application.
WP2Social Auto Publish Powered By : XYZScripts.com