Kotlin 学习地址总结
1 . 官网教程
2 . Anko GitHub
3 . Kotlin Resource
android studio 配置
1 . 当前项目的build.gradle
ext.support_version = '23.1.1'//添加
ext.kotlin_version = '1.0.4'//添加
ext.anko_version = '0.10.1'//添加
repositories {
// jcenter() 更改为
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public'}
}
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() 更改为
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public'}
maven {url 'https://dl.bintray.com/jetbrains/anko'}//添加
}
}
2 . module的build.gradle
中的dependencies {}
下添加以下依赖
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
compile "com.android.support:appcompat-v7:$support_version"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.anko:anko-common:$anko_version"
compile "org.jetbrains.anko:anko-appcompat-v7-listeners:$anko_version"
compile "org.jetbrains.anko:anko-design-listeners:$anko_version"
compile "org.jetbrains.anko:anko-design:$anko_version"
compile "org.jetbrains.anko:anko-sdk15-listeners:$anko_version"
compile "org.jetbrains.anko:anko-sdk15:$anko_version"
compile "org.jetbrains.anko:anko-recyclerview-v7:$anko_version"
Kotlin问题
- 出现Gradle DSL not fund Method问题
compile "org.jetbrains.anko:anko-recyclerview-v7:$anko_version" compile 'com.android.support:appcompat-v7:25.3.1'
更改为:
compile "org.jetbrains.anko:anko-recyclerview-v7:$anko_version"
compile 'com.android.support:appcompat-v7:25.3.1'
不确定,为什么一定要换行才行?
切记切记!!!
compile "....$..."
这个语法必须要buildtoolsVerision大于26.0.1才支持
- 关于
build.gradle
文件中一些变量解释
compileSdkVersion 25 //当前编译的sdk
buildToolsVersion "25.0.2"//构建工程包括 compile等等的工具 必须大于 compileSdkVersion
defaultConfig {
applicationId "adr.ycx.com.testsreen"
minSdkVersion 21 //最低版本 lint在我们写代码时会提示当前api是否满足最低版本
targetSdkVersion 25// 最高版本 一般来说要等于compileVersion 不能大于它
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
java和kotlin互相调用的总结
1 . j use k 类与方法