Kotlin环境篇

来源:互联网 发布:手绘地图软件 编辑:程序博客网 时间:2024/06/14 12:12

Android Studio kotlin环境配置(Mac)

Android Studio ->Plugin ->搜索kotlin —>安装并重启

Kotlin插件安装好之后,可以直接

New ->Kotlin File/Class
New ->kotlin Activity

第一次创建Kotlin类后会提示“Configure Kotlin”,点击之后弹出窗口选择“All modules containing kotlin files”,点击ok。

配置完成之后在项目(APP)的根build.gradle中:

buildscript {    ext.kotlin_version = '1.1.50'    repositories {        jcenter()    }    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    }}allprojects {    repositories {        jcenter()        maven {            url "https://jitpack.io"        }    }}

module的build.gradle中:

apply plugin: 'kotlin-android'android{    ....}dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"}

比较实用的功能

将java代码转换成 kotlin

Code -> Convert Java File to Kotlin File

原创粉丝点击