The first kotlin project and the first kotlin Project

Source: Internet
Author: User
Tags jcenter

The first kotlin project and the first kotlin Project

How to Use Kotlin in Android Studio?

1. Use the Android Studio plug-in

2. Upgrade Android Studio to version 3.0: it is not recommended currently, because version 3.0 is still in the Dev Channel, that is, the development Channel, and has not yet been officially released.

So today we will talk about how to create the first Kotlin project in 1st ways:

Plugin installation:

1. Go to Plugins \ Install JetBrains plugins, search for Kotlin, and Install

2. Create an Android project normally (how to create an Android project at ordinary times or how to create it now), as shown below:

  

Here, I upload it to my Github, so that you can track the records of each change throughout the process.

3. Use a conversion tool to convert java source files to Kotlin.

  

The conversion result is changed as follows: the suffix of the java source file is changed to. kt, and the class inheritance method has changed.

  

4. Configure Kotlin Dependencies

The above operations will add red content to the build. gradle file of the Project.

1 // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 3 buildscript {4 ext. kotlin_version = '1. 1.2-3 '// Kotlin extended attribute 5 repositories {6 jcenter () 7} 8 dependencies {9 classpath 'com. android. tools. build: gradle: 2.2.2 '10 classpath "org. jetbrains. kotlin: kotlin-gradle-plugin: $ kotlin_version "// classpath11 12 required for sub-module build script // NOTE: Do not place your application dependencies here; they belong13 // in the individual module build. gradle files14} 15} 16 17 allprojects {18 repositories {19 jcenter () 20} 21} 22 23 task clean (type: Delete) {24 delete rootProject. buildDir25}

Add red content to build. gradle of the sub-module (app module ).

1 apply plugin: 'com. android. application '2 apply plugin: 'tlin-android' // introduce the kotlin plug-in. If it is a java module, the introduction of the 'tlin' plug-in 3 4 android {5 compileSdkVersion 25 6 buildToolsVersion "25.0.2" 7 defaultConfig {8 applicationId "com. aso. firstkotlin "9 minSdkVersion 1510 targetSdkVersion 2511 versionCode 112 versionName" 1.0 "13 testInstrumentationRunner" android. support. test. runner. androidJUnitRunner "14} 15 buildTypes {16 release {17 minifyEnabled false18 proguardFiles getdefaproproguardfile('proguard-android.txt '), 'proguard-rules. pro '19} 20} 21} 22 23 dependencies {24 compile fileTree (dir: 'libs', include :['*. jar ']) 25 androidTestCompile ('com. android. support. test. espresso: espresso-core: 2.2.2 ', {26 exclude group: 'com. android. support ', module: 'support-annotations' 27}) 28 compile 'com. android. support: appcompat-v7: 25.3.1 '29 testCompile 'junit: 4.12 '30 compile "org. jetbrains. kotlin: kotlin-stdlib-jre7: $ kotlin_version "// Kotlin dependency package 31} 32 repositories {33 mavenCentral () 34}

5. After completing the above four steps, select Sync Gradle (that is, Sync Now event). Congratulations, our first Kotlin project has been created and configured.

6. Next, because we have installed the Kotlin plug-in, when creating a new file, there will be more red options, and then you can create them as needed.

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.