First step: Install the Kotlin plugin
Open the Settings panel, find the Plugins option, click Browse Repositories (browse the warehouse), enter "Kotlin" to find it, and then install it. You will need to restart Android Studio after the installation is complete.
After the installation is complete, as shown in.
Step Two: Configure the Kotlin development environment
Click the Tools option in the menu bar, select Kotlin, and then select Configure Kotlin in Project. As shown in.
In the pop-up window, select the module that needs to use Kotlin and the version of the Kotlin compiler and runtime , as shown in.
After clicking "OK", the Kotlin plugin will start the configuration automatically. Once the configuration is complete, synchronize the project (Sync Project).
In fact, the so-called configuration is changed in the configuration file
First look at the changes in the app's Build.gradle
And look at the total build.gradle.
After configuring the environment, you can convert mainactivity to Kotlin to see the difference between a button's click events before and after the conversion
After conversion before conversion
Convert Java to Kotlin
You can ctrl+alt+shift+k directly in the class that you want to convert, or you can
These operations are completed and then run directly.
Android Studio does not update to the latest version using Kotlin