How to open .KTS files on Android
To open .KTS files on Android, android does not commonly run Kotlin scripts directly; open the file as text for viewing, or transfer it to a desktop system to run with kotlinc -script.
Step-by-step instructions
- Android does not commonly run Kotlin scripts directly; open the file as text for viewing, or transfer it to a desktop system to run with kotlinc -script.
Common issues
Double-clicking doesn’t run the script
.kts files are source code; most operating systems do not execute them by default when you double-click.
- Open the file in a code editor to inspect it as text.
- Run it from a terminal with the Kotlin compiler: kotlinc -script file.kts
Trying to run a Gradle Kotlin DSL file as a standalone script
Files like build.gradle.kts are Gradle build scripts written in Kotlin DSL; they are meant to be evaluated by Gradle, not executed as a generic Kotlin script.
- If the file is named build.gradle.kts (or settings.gradle.kts), treat it as a Gradle build configuration.
- Run it through Gradle as part of the project (not via kotlinc -script).
Script fails because Kotlin tooling isn’t installed or on PATH
Running a .kts file requires the Kotlin command-line compiler (kotlinc). If it is missing or not available in your shell PATH, the command won’t work.
- Install the Kotlin command-line tools.
- Verify kotlinc is available by running: kotlinc -version
- Re-run the script using: kotlinc -script file.kts
Security note
.kts files are executable code when run (for example with kotlinc -script). Only run scripts from sources you trust, because they can perform actions allowed by your user account.