Getting Started with "Kotlin" on Android App Development

9/13/2018

As we evolve and grow with an Android platform, we are excited to see the language to evolve.

The Language - Kotlin is statistically typed opensource language, just like Android under Apache 2.0. It is fully supported in Android studio 3.0 and the higher version of it. This thing has widened, the task of developing a new application with Kotlin files in an easy way. You can write Android apps for Kotlin. Add Kotlin files to your current project and convert Java to Kotlin. Then you have privileges to utilize all of the android studio’s existing tools with your ongoing Kotlin code, for example, link checking, debugging and so on.

What are the benefits of Kotlin

  • Kotlin is mature language as it tested over many years and now the final version is out.
  • Compatible with Android Studio IDE.
  • Quite safer than the Java programming language.
  • It is more reliable and stable.
  • Rapidly growing community and supports developers.
  • Kotlin is multiplatform and profitable.
  • Easy to learn and fun to utilize.

The most exciting features of Kotlin's are: It is expressive; concise; and way too powerful. It is able to exchange and make use of data with the Java programming language. Also, with existing Android runtime environment. For instance, from fortune 500 companies to startups, share the success stories built with Kotlin - Netflix, Udacity - the online learning app, Pinterest, Evernote, Slack. As the world is updated, now it’s your turn to upgrade with the latest trend of the Android App development technology.

Kotlin + Android

Few ensuing steps we are showing you, those are the basic steps on how to get started with Kotlin for your ongoing Java android project. It depends on the project setup or business requirements, it might be needed to keep your running java source code working for as long as it can. You might want to try it out ‘The cool thing’ that is boosting in the android app development market. Then let us uncover the announcement by Google I/O, that is, Kotlin is an officially supported top computing language for an Android ecosystem.

 

This video and tutorial as following will walk you through how to create a basic Kotlin application for Android using Android studio IDE from scratch.

 

 

Step 1: Setup the Kotlin Plugin in Android Studio

The Kotlin plugin is embedded with your Android studio IDE (Any version higher than 3.0). In case you’re using any version below than that, It needs the manual installation of Kotlin plugins. To do so, Navigate to Android Studio → Preferences →Plugins → Browse Repository → type “Kotlin” in search box → Install. You need to perform this action once per installation of android IDE.

Screenshot -1

Done with your installation? Now you might need to restart the android studio.

Step - 2 Create a new android project

Now that your Android studio is already with the Kotlin plugins, let’s move to further step that is - create a new android project in the same exact way we that used to do. Navigate to File → New → New project. Hit the ‘Create empty activity’ option in the end.

Screenshot -2

Step - 3 Apply Kotlin Plugin to the project

Now let's integrate the Kotlin plugins to your project. Albeit, there is an automated tool to perform this, Sometimes the tools create the clumsy situation. We will do the manual process of applying the plugin to build.gradle file.

  • To add Kotlin Gradle plugin: For the configuration, we need to add the plugin priory to root project’s, In a similar way you can do this for Gradle plugin. By adding the plugins to dependencies closure in the project that is in build.gradlefile.It would look same as this:

Screenshot - 3.1

We need to create a variable as shown above. This is because you may have other places in the project that needed a reference to the Kotlin version. If in case we place variable outside the closure, the variable will not be there before the project is completely built, and it will be the false alarm for built action.

  • To apply the Kotlin Android Plugin: After adding the gradle plugin, it is time to apply the plugin. To achieve this, we need to add the apply plugin Kotlin → Kotlin-android to the app modules build.gradle file.

Screenshot - 3.2

Step 4: Convert your Activity java code to Kotlin.

You are all prepared for whatever need to complete this action, though your ‘Empty activity’ generated code is still in the Java programming language. Wait a minute, for us, the Kotlin plugins can help in terms converting the java code to Kotlin.

Right now the java code looks something like this:

Screenshot - 4.1

Now, the final action you need to perform is, Select the File and navigate it to Code → Convert Java file to Kotlin file, or else hit Command + Alt + Shift +K.

After the conversion of our Java code to Kotlin, Our ‘empty Activity; will look like the this:

Screenshot - 4.2

Extra shot: I recommend if you’re really into such an amazing thing about Android, stay updated with your Kotlin versions.

Definitely, it is a pretty much easy job to start and continue with the Kotlin as it is still in trend to be worked on. As the community and the usage is growing so does Kotlin itself (You need to update with all the frequent changes and updates). The Kotlin Android studio IDE plugins help you manage the Kotlin versions. For that navigate to Tools → Kotlin → Configure Kotlin plugin Updates as shown below:

Screenshot - 5

Now you have to select the update channel - ‘’Stable’. Which is currently your edge version.

To get the best out of it, or to be fluent: Reliability over minimized coding logic is recommended. It is obviously a good thing to establish a coding conversation that provides ease to others. Kick start your journey with Kotlin and give your Android programming skill a new experience.

Conclusion:

As the market facing dramatic changes, you might also want to hit the ground? Then Kunsh Technologies a leading Android App Development Company is the answer to your all Android solutions. Hire us and give your ideas a platform to rise above. 

Kunsh Technologies Kunsh Technologies