前言
關(guān)于Kotlin成為Android開發(fā)主力語言的大趨勢我想大家都知道,畢竟Google官方都推薦使用了疲吸,而且最近JakeWharton大神也加入的google.加入的部門是@Android Framework team to work on @Kotlin stuff. 有句話這樣說:跟上大神的腳步。所以我認(rèn)為每一個(gè)Android開發(fā)人員都應(yīng)該學(xué)習(xí)一下Kotlin熊尉,至少不會(huì)讓自己掉隊(duì)塑悼。我打算寫幾篇博客記錄自己在Android開發(fā)中對Kotlin的使用,還可以分享下也許能幫到一些人祟同。
這是一個(gè)系列作喘,這是第一篇講基本安裝使用
安裝使用
由于Android Studio3.0正式版還沒有出來,這里我用的是Android Studio 2.3.3晕城,kotlin_version = '1.1.2-4'泞坦,到時(shí)候3.0正式版出來時(shí)也許會(huì)更新此處
Android Studio 2.3.3
Build #AI-162.4069837, built on June 6, 2017
JRE: 1.8.0_112-release-b06 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
使用Kotlin首先要先有Kotlin,Android studio打開后進(jìn)入項(xiàng)目砖顷,Mac點(diǎn)擊快捷鍵command+,(command加逗號鍵)打開下面的界面贰锁,點(diǎn)擊Plugins ,輸入框搜索Kotlin,已經(jīng)安裝就跳過此步赃梧,沒有安裝點(diǎn)擊下面的Browse respositories搜索安裝
安裝過程可能會(huì)有些慢,我當(dāng)時(shí)好像就裝了挺久的豌熄,主要是外網(wǎng)網(wǎng)速不好
安裝好之后對Kotlin進(jìn)行配置:
打開app Module的build.gradle
buildscript {
ext.kotlin_version = '1.1.2-4'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
}
}
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
...
...
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 "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
}
至此授嘀,應(yīng)該就可以使用Kotlin了
這里新建還會(huì)自動(dòng)新建布局文件,和在注冊文件中注冊
這樣就新建了一個(gè)Kotlin類型的Activity
第一篇完锣险。蹄皱。。