Home » Android with Kotlin

Setup Kotlin with Android Studio | Android with Kotlin

In this article, we are going to learn how to setup kotlin with android studio?
Submitted by Aman Gautam, on August 13, 2018

Since after the google has announced the kotlin as its official language for android app development, it has been significantly raised in the market and development fields. Many apps are already built in with kotlin such as Udacity, Nova launcher, Reddit, Pinterest etc.

With this article let’s start the journey towards developing android apps with kotlin. First of all, if you are new to kotlin I would recommend you to first start with kotlin. Once you get familiar with it will be quite interesting to start the ride.

To start with it, Just install android studiov3.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 version too. But it will add a few more steps in the project compilation. We will discuss them too.

Steps for android studio version 3.0 or higher:

  1. Open android studio.
  2. Create new project.
  3. A window will appear. Name your project, don’t forget to check include kotlin support checkbox.

  4. create android project with kotlin 1

  5. Select form factors and target android devices.
  6. Select Empty Activity (or as per your need).
  7. Click finish, project will start refreshing.
  8. If you wish to create new activity in kotlin then select kotlin as source languagefromthe dropdown.

  9. create android project with kotlin 2

  10. Few files will be created by android studio. But the source file now will be in .kt extension.
  11. You are done.

On previous versions of android studio,

1) Install kotlin plugin first. Just head over to Settings → Plugins.

2) Then click tools → kotlin → configure kotlin in project.

3) The project will be automatically configured, If not then

  • Add these lines in 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 this lines in 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 feature 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:

So from this article, you can now easily setup Kotlin in the 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. And then we will try to get more insights, features that kotlin provides for android. Just stay connected. Good day!






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.