This tutorial walks us through creating a simple Kotlin application for Android.
It’s extremely easy to start using Kotlin for Android development. In this tutorial we’ll follow the warming up process with Android Studio. If you're using Intellij IDEA with Android, the process is almost the same.
First, create a new Kotlin Android Project for your application:
Open Android Studio and click Start a new Android Studio project on the welcome screen or File | New | New project.
Select an activity that defines the behavior of your application. For your first "Hello world" application, select Empty Activity that just shows a screen, and click Next.
In the next dialog, provide the project details:
- name and package
- language: select Kotlin
Leave other options with their default values and click Finish.
Once you complete the steps, Android Studio creates a project. The project already contains all the code and resources for building an application that can run on your Android device or an emulator.
The process of building and running the Kotlin application in Android Studio is exactly the same as with Java.
To build and run your application on an emulator:
- Run the predefined app configuration by clicking Run on the toolbar or Run | Run 'app'.
Select Create New Virtual Device.
Select a device you like and click Next.
Select a system version and download its image.
Verify the emulator configuration and click Finish.
- Click OK and here it is - your first Kotlin application for Android!
Kotlin has a rather small runtime file size: the library is approximately 1298 KB (as of 1.3.61). This means Kotlin adds just a little to .apk file size.
Kotlin compiler produces byte-code, thus there really is no difference in terms of look and feel of Kotlin applications versus those written in Java.
If you want to customize your builds or run configuration, refer to the Android Studio documentation