欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

AndroidStudio kotlin配置详细介绍

程序员文章站 2023-12-02 19:15:46
androidstudio kotlin配置 安装插件 file -> settings -> plugins -> browse reposit...

androidstudio kotlin配置

安装插件

file -> settings -> plugins -> browse repositories -> 搜索 kotlin

gradle添加依赖

module的build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
 
android {
  compilesdkversion 25
  buildtoolsversion "25.0.2"
  defaultconfig {
    applicationid "com.lxs.kotlinconfig"
    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'
    }
  }
}
 
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'<br>
  compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
  compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
}
 
repositories {
  maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}

project的build.gradle

buildscript {
  ext.kotlin_version = '1.1.2-4'
  repositories {
    maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:2.3.2'
    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 {
    maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'}
  }
}
 
task clean(type: delete) {
  delete rootproject.builddir
}
 

kotlin.incremental=true增量编译的机制,可以加快编译速度 项目根目录的gradle.properties里配置

把java代码转换成kotlin代码

code -> convert java file to kotlin file

快捷键 ctrl+alt+shift+k

或者ctrl+shift+a  输入convert java file to kotlin file

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!