In this article, I would like to tell you about 6 ways to run Kotlin code in . Android Studio For example, we will output the string Hello World. println("Hello World!") What can it be useful for This can be useful for quickly checking the results of the . code For example, to make sure that the method is working correctly. Sometimes, it takes a long time to restart the entire project in order to get a single number or string. The examples below allow you to repeatedly run individual, even large pieces of code. The limitation for all these methods is that the code of the method being tested must be independent of the rest of the code of the project. Although the use of dependencies on libraries, for example, , is allowed in some cases. However, it is worth remembering that the more dependencies are used, the longer the code will run. Therefore, the following methods are more suitable for testing an independent method. Gson I am sure that some will be known to you, but some you will find new. 1. Create an empty activity In the usual way, we create a new activity. Insert the line : println("Hello World!") class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) println("Hello World!") } } Do not forget to add it to so as not to crash. Run and get the result: AndroidManifest.xml To find it faster in a huge list of logs, you can enter into the filter. Hello World! 2. Use Kotlin REPL Go to the path Tools > Kotlin > Kotlin REPL The window will open at the bottom of the screen. Insert the line . Start by clicking on the green arrow or by using the combination. Kotlin REPL println("Hello World!") Command+Enter In the same window, just below, you will see the result. You can read more about in . Kotlin REPL this article 3. Create a separate file Create a Kotlin file in any part of the project, for example, . Insert the following lines: Main.kt fun main() { println("Hello World!") } and can run it separately from the entire project. Android Studio has recognized that this is a Kotlin file Click on the green arrow: Below, you can see the results: 4. Use scratch + kotlin script Press the key combination **Command+Shift+N \ Choose Kotlin. The editor window will open, divided into two parts. On the left, you can enter the source code. On the right — see the result. Insert the line . If mode is checked, then you will immediately see the result on the right: println("Hello World!") Interactive You can read about how else to use scratch + Kotlin script in . this article 5. Use Breakpoints Let's go back to the file, created by us earlier (item 3). Main.kt Let's put a opposite the line : Break point println("Hello World!") We will launch it in the debug mode by clicking on the green arrow or by using the combination : Control+Shift+D Insert the line . Note that it is not , because the returned result of the method will be displayed. As you know, returns , so we won't see anything. Press and get the result: "Hello World!" println("Hello World!") println("Hello World!") Unit Enter 6. Use the IDE scripting console Press and type . The following window will be displayed: Command+Shift+A IDE Scripting Console Choose : Kotlin A new file will be created, and an editor window will open. Insert the line into it: println("Hello World!") Next, right-click and press or the key combination : Run Control+Shift+R The Kotlin script will be executed, and we will see the result in the window that appears at the bottom of : Android Studio Also, the file with this script can be found in the path Scratches and Consoles > IDE Consoles > ide-scripting.kts You can read more about the IDE scripting console in . this article Conclusion These simple examples show that that allows you to solve the same task in several ways. This makes it possible to choose the optimal approach or combine several to solve your problems. Android Studio is a fairly flexible tool If you find an error in the article or you have an extension, you can always share it in the comments below.