Run single kotlin class with main function in android studio

后端 未结 15 798
后悔当初
后悔当初 2020-12-13 13:04

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.

<
15条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 13:08

    A less time consuming way would be, configure Android Studio to run Java Program and then call your Kotlin Class from that main method:

    public class JavaApplication{
      public static void main(String[] args){
         KotlinApplicationKt.main(new String[]{});
      }
    }
    

    To configure your android studio to run Java Application: 1. Just add a new configuration(Run Menu > Edit Configurations > + icon ) 2. Select Application & then configure your Main class to your JavaApplication.class 3. Set the working directory to your project directory & JRE as JDK 4. Apply and Run !

提交回复
热议问题