Kotlin Android environment building


Release date:2023-09-21 Update date:2023-10-13 Editor:admin View counts:491

Label:

Kotlin Android environment building

Install the Kotlin plug-in

Android Studio will be installed built-in starting with version 3.0 (preview) Kotlin plug-in.

Open Settings (Mac is Preferences) panel, found on the right Plugins option (command+ under the shortcut key Ctrl+, Mac), enter “Kotlin” in the search box, click Search in repositories (search in warehouse), and then install it. After the installation is completed, you need to restart Android Studio.

Image0

Image1

Create a new project

Choice Start a new Android Studio project or File|New project, mostoptions have default values, you only need to press the”enter” key a fewtimes.

Image2

Android Studio 3.0 provides the option to enable Kotlin support in the current dialog box. When checked, you can skip the “configure Kotlin Project (Configuring Kotlin in the project)” step.

Select the Android version:

Image3

Select what you need to create Activity style:

Image4

Name the Activity :

Image5

In Android Studio 3.0, you can choose to use the Kotlin create activity so the “convert Java code to Kotlin (Converting Java code to Kotlin)” step is not required.

In previous versions, Java was used to create the activity and then convert using the automatic conversion tool.

Convert Java code to Kotlin

Reopen Android Studio, create a new Android project, and add a default MainActivity

Open MainActivity.java file, call up Code|Convert Java File to Kotlin File through the menu bar:

Image6

After the conversion is complete, you can see the use of the Kotlin written by activity .

Image7

Configure Kotlin in the project

When you start editing this file, Android Studio will prompt you that the current project has not been configured Kotlin follow the prompts to complete the operation, or you can select Tools

Image8

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

Image9

After the configuration Kotlin is complete, the application’s build.gradle file will be updated. You can see the addition of applyplugin: ‘kotlin-android’ and its dependencies.

Image10

To synchronize the project, click “Sync Now” in the prompt box or use the Sync Project with Gradle Files orders.

Image11

Powered by TorCMS (https://github.com/bukun/TorCMS).