Android Studio 添加Kotlin extensions 和lambda支持

版权声明:本文为博主原创文章,未经博主允许不得转载。 - long for us https://blog.csdn.net/longforus/article/details/62898050

要添加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
  }
  //~~~~~~~~~~~~~~
}


猜你喜欢

转载自blog.csdn.net/longforus/article/details/62898050