Kotlin--Hello World

放在前面的圖

Kotlin吐槽

kotlin出來好早了 我記得15年還是16年 當(dāng)時看過一陣子 入了個門 Hello World 簡單的看了下語法 當(dāng)時覺得和 C#好像啊 后來沒怎么繼續(xù)看只記得 好像不能彈吐司 最近這段時間特別火 特別是宣布成為android官方語言之后 尤其是Android Studio 3.0上默認(rèn)支持Kotlin。我的是AS 是2.3版本 所以需要安裝插件。

Android Studio環(huán)境搭建

執(zhí)行 Settings -> plugins -> BrowseRepositories中搜索“Kotlin” 安裝重啟

project的build.gradle配置:

buildscript新增ext.kotlin_version = '1.1.2-4'
dependencies新增classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
allprojects新增mavenCentral()

module的build.gradle配置

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

為避免遺漏:
<code>

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.1.2-4'
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        //Kotlin
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

ext {
    buildToolsVersion = '25.0.3'
    supportLibVersion = '25.3.1'
    runnerVersion = '0.5'
    rulesVersion = '0.5'
    espressoVersion = '2.2.2'
    archLifecycleVersion = '1.0.0-alpha1'
    archRoomVersion = '1.0.0-alpha1'
}

</code>

<code>

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
    compileSdkVersion 25
    buildToolsVersion rootProject.ext.buildToolsVersion
    defaultConfig {
        applicationId "com.kotlin.kotlindemo"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags ""
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:    espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'

    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

</code>

所有都配置好了之后,選擇一個Activity文件,選擇code->convet java file...

感謝:
http://www.itdecent.cn/p/a6f8dcd6a330
http://wuxiaolong.me/2017/05/21/kotlin1/
最近在寫Kotlin的demo 還在學(xué)習(xí)ing

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容