Android Studio 配置Kotlin詳解

插件安裝

安裝這個kotlin插件


Paste_Image.png
  1. project的build.gradle配置
  1. buildscript新增ext.kotlin_version = '1.1.2-4'
  2. dependencies新增classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  3. allprojects新增mavenCentral()
  1. module的build.gradle配置
  1. 新增插件支持
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
  1. android新增
 sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
  1. dependencies新增
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

總配置

// 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.3.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.happy.kotlindemo"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
}
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:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

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

Paste_Image.png

大功告成

Paste_Image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市吨掌,隨后出現(xiàn)的幾起案子收擦,更是在濱河造成了極大的恐慌,老刑警劉巖秦忿,帶你破解...
    沈念sama閱讀 222,378評論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件内颗,死亡現(xiàn)場離奇詭異捻激,居然都是意外死亡制轰,警方通過查閱死者的電腦和手機前计,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,970評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來艇挨,“玉大人残炮,你說我怎么就攤上這事∷醣酰” “怎么了势就?”我有些...
    開封第一講書人閱讀 168,983評論 0 362
  • 文/不壞的土叔 我叫張陵,是天一觀的道長脉漏。 經(jīng)常有香客問我苞冯,道長,這世上最難降的妖魔是什么侧巨? 我笑而不...
    開封第一講書人閱讀 59,938評論 1 299
  • 正文 為了忘掉前任舅锄,我火速辦了婚禮,結(jié)果婚禮上司忱,老公的妹妹穿的比我還像新娘皇忿。我一直安慰自己,他們只是感情好坦仍,可當我...
    茶點故事閱讀 68,955評論 6 398
  • 文/花漫 我一把揭開白布鳍烁。 她就那樣靜靜地躺著,像睡著了一般繁扎。 火紅的嫁衣襯著肌膚如雪幔荒。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,549評論 1 312
  • 那天梳玫,我揣著相機與錄音爹梁,去河邊找鬼。 笑死提澎,一個胖子當著我的面吹牛姚垃,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播盼忌,決...
    沈念sama閱讀 41,063評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼积糯,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了碴犬?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,991評論 0 277
  • 序言:老撾萬榮一對情侶失蹤梆暮,失蹤者是張志新(化名)和其女友劉穎服协,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體啦粹,經(jīng)...
    沈念sama閱讀 46,522評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡偿荷,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,604評論 3 342
  • 正文 我和宋清朗相戀三年窘游,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片跳纳。...
    茶點故事閱讀 40,742評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡忍饰,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出寺庄,到底是詐尸還是另有隱情艾蓝,我是刑警寧澤,帶...
    沈念sama閱讀 36,413評論 5 351
  • 正文 年R本政府宣布斗塘,位于F島的核電站赢织,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏馍盟。R本人自食惡果不足惜于置,卻給世界環(huán)境...
    茶點故事閱讀 42,094評論 3 335
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望贞岭。 院中可真熱鬧八毯,春花似錦、人聲如沸瞄桨。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,572評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽讲婚。三九已至尿孔,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間筹麸,已是汗流浹背活合。 一陣腳步聲響...
    開封第一講書人閱讀 33,671評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留物赶,地道東北人白指。 一個月前我還...
    沈念sama閱讀 49,159評論 3 378
  • 正文 我出身青樓,卻偏偏與公主長得像酵紫,于是被迫代替她去往敵國和親告嘲。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,747評論 2 361

推薦閱讀更多精彩內(nèi)容