Monday, April 13, 2020

Kotlin Android environment setup

Install Kotlin plugin
Android Studio will install Kotlin plug-in from version 3.0 (preview).
Open the Settings (Mac Preferences) panel, find the Plugins option on the right (shortcut Ctrl +, Command + under Mac), enter "Kotlin" in the search box, click Search in repositories (search in the warehouse), then install it, install After completion, you need to restart Android Studio.
Kotlin Android environment setup

Create a new project
Choose Start a new Android Studio project or File | New project, most options have default values, just press the "Enter" key a few times.

Android Studio 3.0 provides the option of enabling Kotlin support in the current dialog box. After checking, you can skip the step of "Configuring Kotlin in the project".
Select Android version:

Select the Activity style to be created:
Name the Activity:


In Android Studio 3.0, you can choose to use Kotlin to create activities, so there is no need to "Convert Java code to Kotlin (Converting Java code to Kotlin)" step.
In earlier versions, you will first use Java to create the activity, and then use the automatic conversion tool for conversion.
Convert Java code to Kotlin
Reopen Android Studio, create a new Android project, add a default MainActivity
Open the MainActivity.java file, and call Code | Convert Java File to Kotlin File through the menu bar:

After the conversion is complete, you can see the activity written in Kotlin.

Configure Kotlin in the project
When starting to edit this file, Android Studio will prompt that Kotlin has not been configured for the current project, and follow the prompts to complete the operation, or you can select Tools in the menu bar

When selecting configuration, there is the following dialog box, just select the latest version installed.

After the Kotlin configuration is complete, the application's build.gradle file will be updated.

You can see the newly added apply plugin: 'kotlin-android' and its dependencies.
Tags: Kotlin Android environment setup,Kotlin Environment Setup IDE,Beginning Android Development with Kotlin,Kotlin Tutorial

No comments:

Post a Comment