
In my previous articles, we learned the basics of Kotlin and getting started with Android application development with Kotlin. If you are new to Kotlin, read my previous articles.
In this article, we will learn about Kotlin Android Extensions. We already know Kotlin was announced as a first class language for Android by Google in Google I/O 2017. Kotlin Android Extensions is an important Kotlin plugin that is similar to ButterKnife. It will allow recovering Views in Android.
Coding Part
I have split this article into 3 steps as in the following.
Step 1: Creating a New Android Project with Kotlin in Android Studio.
Step 2: Setting Up the Library for Android Projects.
Step 3: Implementing Kotlin Extensions in Android Applications.
Step 1: Creating a New Android Project with Kotlin in Android Studio
By default, Android Studio 3.0 has the checkbox for Kotlin Support for your Android Application. Create a new project in Android Studio, check the Kotlin support, and start as usual with Android Studio 3.0. 
For migrating Java Android Project to Kotlin Android Project, you can do the following processes.
Configuring Kotlin
Kotlin support can be configured by selecting Tools à Kotlin à Configure Kotlin. Then, Click “Sync Now”. This step is applicable to the Android Studio pre-versions of 3.0. The best way is you must update your Android Studio.
In Android Studio 3.0, by default, you have Kotlin Activity. For Android Studio with versions lower than 3.0, users can convert their Java activity into Kotlin Activity.
Open Quick Search or Click Ctrl + Shift + A for Windows Users and Search and Select “Convert Java to Kotlin” or simply Select Ctrl + Shift + Alt + K.
Step 2: Setting Up the Library for Android Projects
In this step, we will learn how to setup Kotlin Extensions in Android Application. You have to add the following line in your project’s app-level build.gradle file.
- apply plugin:'com.android.application'
- apply plugin:'kotlin-android'
- apply plugin:'kotlin-android-extensions'
Then click “Sync Now” to add the library.
Step 3: Implementing Kotlin Extensions in Android Application
Create a new layout file in res folder, name it activity_main.xml, and paste the following codes.
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="center"
- android:orientation="vertical"
- tools:context="com.androidmads.kotlinsample_helloworld.MainActivity">
- <TextView
- android:id="@+id/helloTxtView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Hello World!" />
- <TextView
- android:id="@+id/helloAndroidExtension"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="10dp"
- android:text="Hello World!" />
- <ImageView
- android:id="@+id/imageView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="10dp"
- app:srcCompat="@mipmap/ic_launcher" />
- </LinearLayout>

Abubackkar ShithikPosted Jun 20, 2019, 2:11 AM
Nice article
Sagar Pandurang KapPosted Feb 25, 2018, 10:35 PM
Welll described......Keep sharing....