Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
Run a single .kt file in Android Studio

I created a Scratch Kotlin file in Android Studio. I simply want to run this scratch.kt file and get output.

I fiddled with Run Cofigurations but cannot understand what will go into Main Class.

enter image description here

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

If you create a top-level function called main in any kotlin file, a green run button will appear next to it that allows you to run it as a program:
enter image description here

Note that this works in Android Studio as well as in IntelliJ IDEA.

over 4 years ago · Santiago Trujillo Relatório

0

You can create a scratch kotlin file with File -> New -> Scratch File -> Kotlin. With this you should be able to create and run kotlin script files to try features, code and so on.

If your intention is to create a full standlone kotlin project. My recomendation is to use IntelliJ IDEA. Doing so with Android Studio may be possible but you won't stop facing issues and having to search for workarounds all the time.

over 4 years ago · Santiago Trujillo Relatório

0

Android Studio allow to run Kotlin code, but the green triangle (to Run) appears just if you don't use a class file or if you add a fun main(args: Array<String>){} out of the class's brackets. So, the way I am doing this (in AS 4.0) is:

  1. Creating a Kotlin FILE (not choose a CLASS) and putting inside just:

    fun main(args: Array) {}

  2. Then, inside this method you are allowed to use Kotlin classes. You can do for example:

    fun main(args: Array){ var oneMan: Man = Man() oneMan.method() }

being Man a regular Kotlin class.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda