要添加extensions才能直接使用xml内的ID
在project级别的gradle中添加:
buildscript {
ext.kotlin_version = '1.1.1'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
//~~~~~~
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
//~~~~~~~
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
在app级别添加 apply:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'//启用扩展支持直接使用ID
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.longforus.kotlintest"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//~~~~~~~~~ 添加1.8 lambda 支持1
jackOptions {
enabled true
}
//~~~~~~~~~~~~
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
//~~~~~~~~~~~~ 添加1.8 lambda 支持2
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
//~~~~~~~~~~~~~~
}