YouTip LogoYouTip

Otlin Android Setup

## Install Kotlin Plugin Starting from version 3.0 (preview), Android Studio comes with the Kotlin plugin built-in. Open the Settings (Preferences on Mac) panel, find the Plugins option on the right (shortcut Ctrl+, or command+ on Mac), type "Kotlin" in the search box, click "Search in repositories", and then install it. After installation, you need to restart Android Studio. !(#) !(#) * * * ## Create a New Project Select "Start a new Android Studio project" or File | New project. Most options have default values, so you can simply press "Enter" a few times. !(#) Android Studio 3.0 provides an option to enable Kotlin support in the current dialog. Checking this option allows you to skip the "Configuring Kotlin in the project" step. Select the Android version: !(#) Choose the Activity style to create: !(#) Name the Activity: !(#) In Android Studio 3.0, you can choose to create the Activity using Kotlin, so the step of "Converting Java code to Kotlin" is also not required. In earlier versions, you would first create the Activity in Java and then use the automatic conversion tool to convert it. * * * ## Convert Java Code to Kotlin Reopen Android Studio and create a new Android project, adding a default MainActivity. Open the MainActivity.java file and navigate through the menu bar to Code | Convert Java File to Kotlin File: !(#) After the conversion is complete, you will see the Activity written in Kotlin. !(#) ### Configure Kotlin in the Project When you start editing this file, Android Studio will prompt that Kotlin is not yet configured in the current project. Follow the prompts to complete the operation, or you can select Tools from the menu bar. !(#) When configuring, the following dialog box will appear. Select the latest installed version. !(#) After Kotlin configuration is complete, the application's build.gradle file will be updated. You will see the addition of `apply plugin: 'kotlin-android'` and its dependencies. !(#) Synchronize the project by clicking "Sync Now" in the prompt box or using the "Sync Project with Gradle Files" command. !(#)
← Kotlin Loop ControlKotlin Tutorial β†’