Android Studio 集成 kotlin
来源:互联网 发布:iphone怎么快速开数据 编辑:程序博客网 时间:2024/06/13 00:58
[kotlin 官网](http://kotlinlang.org)[kotlin 源码地址](https://github.com/JetBrains/kotlin)在android 开发中,目前不仅限与java语言,google推出kotlin语言专门进行android开发,同时100%兼容java语言,而且kotlin语言比java语言更加简单
安装插件
使用AndroidStudio -> File -> Settings -> Plugins -> Browse repositories -> 搜索 kotlin ,然后选择哪个名字为 Kotlin 的安装就好,其他的任何都可以不要。
Gradle添加依赖
Module的build.gradle
apply plugin: ‘com.android.application’
apply plugin: ‘kotlin-android’ //添加
apply plugin: ‘kotlin-android-extensions’ //添加
android {
compileSdkVersion 26
buildToolsVersion “26.0.0”
defaultConfig {
applicationId “com.example.administrator.freepro”
minSdkVersion 15
targetSdkVersion 26
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 “org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version”
compile ‘com.android.support:appcompat-v7:26.+’
compile ‘com.android.support.constraint:constraint-layout:1.0.2’
testCompile ‘junit:junit:4.12’
}
repositories {
mavenCentral()
}
测试
打开你的MainActivity,AndroidStudio工具栏 -> Code -> Convert Java File to Kotlin Fileimport android.app.Activityimport android.os.Bundleimport kotlinx.android.synthetic.main.activity_main.*class MainActivity : Activity(){ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) tv.text = "textview" }}kotlin中可以直接使用控件的ID来获取控件,不需要findViewbyId()方法,同时可以id.属性名来修改属性,例:tv.text = "textview"注:在编译的时候有一个增量编译的机制,可以加快编译速度,在目录的gradle.properties里添加kotlin.incremental=true摘自[http://www.cnblogs.com/princenwj/p/6888226.html](http://www.cnblogs.com/princenwj/p/6888226.html)
- Android Studio 集成 kotlin
- Android studio快速集成Kotlin
- Android Studio 集成Kotlin遇到的错误
- Kotlin在Android中的应用之Studio集成Kotlin(一)
- 集成Kotlin到Android
- android studio kotlin
- android studio配置kotlin
- android studio 3.0 kotlin
- Android Studio 配置Kotlin
- Android Studio+Kotlin初探
- Android Studio配置Kotlin
- Android-studio&Kotlin
- Android Studio配置kotlin
- 【Kotlin】Android Studio 配置
- android studio入门Kotlin
- Kotlin + android Studio
- Kotlin学习系列----Android Studio配置Kotlin
- android studio 配置kotlin 环境
- BZOJ 2463 谁能赢呢?[博弈论]
- Javascript 脚本语言详解
- 启动hadoop时,datanode启动不起来的问题
- java常用2种for循环的区别
- Java基本方法——String数组转List,删除List1中与List2中相同的元素
- Android Studio 集成 kotlin
- 详解location.href几种用法
- 应用被强杀
- Web应用的负载均衡、集群、高可用的解决方案---解决高并发
- autocomplete使い方
- Effective C++ 知识点记录
- linux platform设备驱动全透析
- 第一篇博客
- Kafka配置