

We can see a considerable difference in the Java and Kotlin syntax. Unlike Java, Kotlin requires explicit annotations for overridable members for overrides. ‘override’ becomes part of the onCreate function and the function syntax is changed to ‘fun onCreate’ in Kotlin. In Kotlin, the declaration of a variable name is followed by a ‘:’, after which the datatype is specified.ģ. extends AppCompatActivity is changed to: AppCompatActivity(). The following differences can be noted:ġ. For other versions, the user needs to convert the existing Java class to Kotlin, by opening the MainActivity.java file, and then selecting Code > Convert Java file to Kotlin file (Figure 2).įigure 3 shows the differences between Java class and Kotlin class. Checking the box will enable Kotlin, and this is the starting activity - the MainActivity (default name) named MainActivity.kt.

The slide asking for the project’s name will have an option underneath, ‘ Include Kotlin Support’. Now, add the following line to the adle (Module: app) file, as the second line, followed by the plugin: apply plugin: ‘kotlin-android’ Figure 1: Adding Kotlin to Android Studio Figure 2: Converting Java to KotlinĪndroid Studio 3.0 users can directly select Kotlin as their default language while creating a new project as usual, select File > New > New Project.

classpath “:kotlin-gradle-plugin:$kotlin_version”Ĭlasspath “:kotlin-android-extensions:$kotlin_version”Īlso add the Kotlin version into the buildscript section, as follows: ext.kotlin_version = ‘1.1.x’ Now, if the Android Studio version is not 3.0, we need to add the following code into the adle (Project: MyApplication) file (located at the bottom of the left side of the Project window, inside Gradle Scripts), under the dependencies section.
