AndroidStudio kotlin配置详细介绍

作者:蹭饭熊 时间:2022-02-18 14:09:21 

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

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

来源:http://www.cnblogs.com/QQ80565970/p/6915046.html

标签:Android,kotlin
0
投稿

猜你喜欢

  • 配置springboot项目使用外部tomcat过程解析

    2021-11-22 22:34:25
  • SpringBoot中使用Redis Stream实现消息监听示例

    2021-09-02 04:42:07
  • mybatis foreach遍历LIST读到数据为null的问题

    2021-05-24 20:15:27
  • SpringCloud2020整合Nacos-Bootstrap配置不生效的解决

    2023-11-29 02:42:47
  • 关于Android中Gradle和jar包下载慢的问题及解决方法

    2022-08-29 00:50:21
  • 聊聊Redis的单线程模型

    2022-02-21 09:20:42
  • SparkSQL开窗函数分析使用示例

    2022-04-16 02:26:32
  • 分析SpringBoot的启动原理

    2021-10-30 16:01:23
  • C语言由浅入深讲解文件的操作下篇

    2022-12-05 21:21:54
  • 关于SpringCloudStream配置问题

    2023-08-08 20:12:00
  • Flutter应用集成极光推送的实现示例

    2023-06-24 03:51:04
  • 使用java采集京东商城行政区划数据示例

    2023-04-17 06:31:52
  • C# DateTime日期比较方法案例详解

    2021-11-09 15:32:47
  • 深入剖析Java中String类的concat方法

    2023-06-02 07:07:13
  • 分享Android仿刮奖效果控件

    2021-12-15 16:00:16
  • Android自定义View实现水面上涨效果

    2023-03-02 22:13:06
  • Spring Data Jpa框架最佳实践示例

    2021-11-25 00:43:01
  • SpringBoot修改子模块Module的jdk版本的方法 附修改原因

    2023-07-23 21:05:20
  • MyBatis全局配置文件详解

    2021-09-19 10:13:32
  • 浅谈Java 继承接口同名函数问题

    2023-07-22 13:28:47
  • asp之家 软件编程 m.aspxhome.com