Monday, July 24, 2017

Configure Kotlin Plugin to Android Studio

Kotlin is a new programming language Developed by JetBrains.


This article about
1.How to configure Kotlin plugin to Android Studio.
2. Create Hollo world App.

Install Kotlin Plugin to Android Studio 

File -> Settings -> Plugins - > Browse Repositories -> Search  -> Kotlin -> Install



Create new Android Project and Apply Kotlin Plugin to your project.

Apply Kotlin to your project

buildscript {
    ext.kotlin_version = "1.0.6" // replace with the latest (stable) version: https://github.com/JetBrains/kotlin/releases/latest

    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android' // apply kotlin android plugin


Convert Activity java code to Kotlin 

This is java code

package world.hello.kotlin.kotlinfirstproject;

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

public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}





After Conversion

package world.hello.kotlin.kotlinfirstproject

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

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}






No comments:

Post a Comment

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...