Search code examples
androidkotlingradle-kotlin-dsl

What's the difference between .kt and .kts files in Kotlin. When should we use .kts file over .kt file?


What is the purpose of using .kts files in Kotlin? Are these files included in the app bundle when releasing the app?

enter image description here


Solution

  • .kt — normal source files, .kts — script files

    You don't need the main function in a .kts file, It will be executed line by line just like a bash/python script.

    The .kts files don't need separate compilation. You run them using the following command:

    kotlinc -script <filename>.kts