Kotlin(二)
来源:互联网 发布:c语言培训班哪个机构好 编辑:程序博客网 时间:2024/06/12 00:51
配置Gradle
首先,你需要如下修改父build.gradle:
buildscript { ext.kotlin_version = '1.1.2-4' ext.anko_version = '0.8.2' repositories { jcenter() } 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 { jcenter() }}task clean(type: Delete) { delete rootProject.buildDir}
其次,在app下的build.gradle中:
apply plugin: 'com.android.application'apply plugin: 'kotlin-android'android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.zhoujian.testactivity" minSdkVersion 11 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' } }}sourceSets { main.java.srcDirs += 'src/main/kotlin'}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 "org.jetbrains.anko:anko-common:$anko_version" compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4' testCompile 'junit:junit:4.12'}repositories { mavenCentral()}
重新Make project
把MainActivity转换成Kotlin代码
选中MainActivity,然后选择Code -> Convert Java File to Kotlin File
package com.zhoujian.kotlindemoimport android.os.Bundleimport android.support.v7.app.AppCompatActivityclass MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) }}
阅读全文
0 0
- Kotlin(二)
- 一步一步学习Kotlin(二)
- Kotlin基本使用二
- Kotlin语法(二)
- 一周入门Kotlin(二)
- Kotlin 基本语法 (二)
- 学习一下Kotlin(二)
- Kotlin 基本类型 (二)
- kotlin基本语法(二)
- Kotlin Reference (二) Idioms
- Kotlin编程之二
- Kotlin基础知识二
- kotlin语法学习二
- kotlin之springboot二
- kotlin语法分析(二)
- kotlin学习(二)
- Kotlin学习教程(二)
- Kotlin学习(二)
- 判断是否是微信浏览器
- hellocharts实现y轴固定和x轴滑动效果
- jquery easyui datagrid 分页实现
- 魅族大数据之流平台设计部署实践
- 道格拉斯-普克算法
- Kotlin(二)
- Unity实现画线条功能
- mysql 大数据查询优化
- 四条命令, 完成 centos 7 安装 openstack
- 机器学习中用来防止过拟合的方法有哪些?
- iOS UI控件和对象的一些常用但不容易记忆的属性、接口归纳
- 如何将abc,倒叙输出
- 软件测试技术路线怎么走
- 微信二维码生成接口