AndroidStudiokotlin配置详细介绍

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

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

新闻标题:AndroidStudiokotlin配置详细介绍
网站URL:https://www.cdcxhl.com/article34/poohse.html

成都网站建设公司_创新互联,为您提供网站营销网站内链网站维护定制网站做网站外贸建站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都做网站