AndroidStudio kotlin AndroidStudio kotlin配置仔细讲解

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

AndroidStudio kotlin AndroidStudio kotlin配置仔细讲解

蹭饭熊   2021-03-24 我要评论
想了解AndroidStudio kotlin配置仔细讲解的相关内容吗,蹭饭熊在本文为您仔细讲解AndroidStudio kotlin的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:AndroidStudio,kotlin配置,Android,kotlin配置,下面大家一起来学习吧。

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

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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们