Kotlin的配置和使用
来源:互联网 发布:罗慕路斯 知乎 编辑:程序博客网 时间:2024/06/05 22:41
在Google I/O 2017中,Google 宣布 Kotlin 成为 Android 官方开发语言。
本文是在android studio(2.3.1)中使用的方法,别的开发开发工具要自己找答案。(可以查看http://www.runoob.com/kotlin/kotlin-eclipse-setup.html )给菜鸟教程打广告啦!
步骤:
1.在android studio中点击setting—plugins—输入kotlin—-install—-重启android studio 。
2.配置:在project中找build.gradle添加代码:
// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript { //需要加入代码 ext.kotlin_version = '1.1.2-4' ext.anko_version = '0.10.0-beta-2' repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.1' //需要加入的代码 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 { jcenter() }}task clean(type: Delete) { delete rootProject.buildDir}
在app中的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.miio.demoaggregate" 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 'com.android.support:appcompat-v7:26.+' compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' //需要加入代码 compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" compile "org.jetbrains.anko:anko-common:$anko_version"}
是不是很简单啊!
3.Android切换到kotlin语言:点击code—– Convert Java File to Kotlin File就可以了。
4.Kotlin转换到Android:如果不想使用kotlin在代码中点击右键—-local history只能回到没有编写kotlin以前不能保存写过的代码。
5.来一个简单toast
import android.os.Bundleimport android.support.v7.app.AppCompatActivityimport org.jetbrains.anko.toastclass KotlinActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) toast("Hello Kotlin"); }}
学习ing,加油!
阅读全文
0 0
- Kotlin的配置和使用
- kotlin 的配置及使用
- Android studio中Kotlin配置和使用的图文详解
- KotLin的简单使用 KotLin入门基础 AndroidStudio中配置KotLin插件 新建KotLin工程
- Kotlin配置与使用
- AndroidStudio配置使用Kotlin
- Kotlin编程之类的介绍和使用
- Kotlin的配置(一)
- Kotlin语法和使用
- Kotlin的初窥之kotlin配置
- Android Studio 配置使用 Kotlin
- android studio 使用kotlin编写architecture componets的配置问题
- 1.kotlin 配置和环境
- Android急速开发--kotlin环境配置和遇到的问题
- Kotlin的使用记录
- Kotlin 分支的使用
- Kotlin的初步使用
- Kotlin:Google让我们使用Kotlin的理由
- 《算法导论》第21章 用于不相交集合的数据结构 个人笔记
- [最新] Visual Studio工程文件清理工具V1.1
- PHP实现图片压缩同时保持清晰度
- java Collections.sort()实现List排序的默认方法和自定义方法
- MySQL位数据类型
- Kotlin的配置和使用
- MongoDB学习笔记(二)
- 一元夺宝
- git add和git commit的区别
- linux端口被占用情况
- 基于R-CNN的物体检测
- Trafodion/EsgynDB 性能优化求生指南
- 高考估分查分选志愿一键搞定_支付宝又操办了件人生大事
- Java 数组