Home »
Android with Kotlin
Setup Kotlin with Android Studio | Android with Kotlin
By IncludeHelp Last updated : December 04, 2024
Introduction
Since after Google has announced Kotlin as its official language for android app development, it has significantly risen in the market and development fields. Many apps are already built with Kotlin such as Udacity, Nova Launcher, Reddit, Pinterest, etc.
With this article, let’s start the journey toward developing Android apps with Kotlin. First of all, if you are new to Kotlin, I recommend you first start with Kotlin. Once you get familiar with it, it will be quite interesting to start the ride.
Requirements
To start with it, just install Android Studio v3.0 or higher, as Kotlin is fully supported in versions >=3.0. Also, it's easy to create new projects with Kotlin files, add Kotlin files to your existing project, and convert Java language code to Kotlin. You can use it in the previous versions too, but it will add a few more steps to the project compilation. We will discuss them too.
Steps for Android Studio Version 3.0 or Higher
- Open Android Studio.
- Create a new project.
- A window will appear. Name your project, and don’t forget to check the "Include Kotlin Support" checkbox.
- Select form factors and target Android devices.
- Select "Empty Activity" (or as per your need).
- Click "Finish"; the project will start refreshing.
- If you wish to create a new activity in Kotlin, select Kotlin as the source language from the dropdown.
- Android Studio will create a few files, but the source file will now have a .kt extension.
- You are done.
On Previous Versions of Android Studio
1) Install the Kotlin plugin first. Just head over to Settings → Plugins.
2) Then click Tools → Kotlin → Configure Kotlin in the project.
3) The project will be automatically configured. If not, then:
- Add these lines in the project-level build.gradle dependencies block:
classpath 'com.android.tools.build:gradle:2.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Add these lines in the module-level build.gradle file at the top of the page:
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
// Kotlin extension to add extra features and reduce lines of code
In the dependency block:
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
4) Refresh/build your project.
5) You are done.
Conclusion
From this article, you can now easily setup Kotlin in Android Studio. If you face any doubt or confusion, just write it down in the comment section. In the next article, we will build our first Android app with Kotlin. Then, we will explore more insights and features that Kotlin provides for Android. Stay connected. Good day!