I am trying to get familiar with Kotlin to use in my android apps. So first I want to try out some simple kotlin examples, just to get familiar with syntax of kotlin.
<It is supported now (V 3.2.1 )
I just finished upgrading my Android studio, created A new project I then waited until all the building finished ( if you are advised to upgrade something please accept )
After that I created a new Kotlin file and added your code, right click and choose the Run option and that's it .
I can see the following in the console
Hello World
Process finished with exit code 0
Update:
Approach 1:
Now you can create a kotlin file with empty main()
method and then you can run the code directly using run icon on left(of 7th line) in android studio (AS version: 3.5.3 ) editor like
This will internally create the TestKt(name of file) class
with PSVM
method(and required structure) to execute the code.
Demo configuration(automatically generated) to run this file will look like
Approach 2(with Scratch file, tested on AS 3.6):
Project
view in the project navigation panel.New -> Scratch File -> Kotlin
Android studio (intellij) provides REPL(Real Eval Print Loop) tool to write and execute kotlin code.
Tool -> kotlin -> kotlin REPL
Either write code or import
the class
Tips:
This is simply not possible as of now in Android Studio 3.0.
There is a bug filed for this already: https://issuetracker.google.com/issues/68021152