1. Kotlin是什么毛肋?為什么選用它?
Kotlin 是一門把 Java 平臺作為目標(biāo)的新的編程語言神帅。
它簡潔权谁、安全氯庆、優(yōu)雅而且專注于和 Java 代碼間的互操作性。
Kotlin 能夠很好的與現(xiàn)有的 Java 庫和框架并存。而且,它運(yùn)行的性能不亞于 Java 杖狼。
2.Kotlin在Android中的配置
如果使用android studio 3.0及以上版本的話可以直接忽略本次配置步驟
PS:集成 Kotlin 到現(xiàn)有的安卓應(yīng)用里面是十分容易的,
只需要使用免費(fèi)的 Android Studio 的 Kotlin 插件妖爷。
- step1:選擇android studio 下的 Preferences選項
image.png
- step2:在plugins選項中蝶涩,右側(cè)的文本框中鍵入Kotlin,然后選擇Browse repositories...
image.png
- step3:選中Kotlin插件絮识,然后install
image.png
-
step4:在工程中的具體配置
apply plugin: 'kotlin-android' compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" repositories { mavenCentral() }
image.png
-
step5:配上Kotlin的版本信息
buildscript { ext.kotlin_version = '1.1.3-2' repositories { jcenter() maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } maven { url "https://dl.google.com/dl/android/maven2/" } } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' 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 } } 自此基本配置完成就可以開始使用Kotlin開發(fā)Android了绿聘,而且還可以和JAVA無縫切換