Make Kotlin file Runnable/Executable on Android Studio

Vikram Hooda
2 min readDec 21, 2018

It’s a quick guide on how to run a Kotlin file i.e .kt extension file when using Android Studio as an IDE.
In brief: If you have already a project and just want to run the Kotlin file then you must have fun main(args: Array<String>){} function.

Steps to run the Kotlin file(.kt):-

  1. Create a new Android Project.
Create an Android Project

2. Choose “Add No Activity” option from the template and Finish.

Choose “Add No Activity”

3. Right-click on the directory and create a new Kotlin File.

Choose a new Kotlin file

4. Give a name to file which will have .kt extension.

HelloKotlinWorld.kt

5. Once you will define the main function, then you will see a run icon. Just tap it and you are done. :)

run icon to run .kt extension file

It must have a “main” function in the Kotlin file to make it runnable. If you have main() function then this project can be a pure Kotlin project without using any android libraries.

fun main(args: Array<String>){
println(printHello())
}

fun printHello(): String {
return "Hello Kotlin World!"
}

6. Edit Config will have this class as Main class. You can change if have multiple runnable Kotlin files.

Edit config Kotlin

Have happy coding and a clap. :-)

--

--

Vikram Hooda
Vikram Hooda

Written by Vikram Hooda

Love Your Work, World will love you:- VK

No responses yet