[Gradle Retrolambda]Android Studio使用lambda表达式

来源:互联网 发布:淘宝密码忘了怎么办 编辑:程序博客网 时间:2024/06/06 02:51

1.下载jdk8

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

2.配置Project: build.gradle

buildscript {    repositories {        mavenLocal()        jcenter()    }    dependencies {        classpath 'com.android.tools.build:gradle:1.5.0'        classpath 'me.tatarka:gradle-retrolambda:3.2.5'    }}allprojects {    repositories {        jcenter()    }}task clean(type: Delete) {    delete rootProject.buildDir}

3. 配置Module:app -> build.gradle文件

添加apply plugin:

apply plugin: 'me.tatarka.retrolambda'

在android 节点下增加compileOptions:

android {    compileOptions {        sourceCompatibility JavaVersion.VERSION_1_8        targetCompatibility JavaVersion.VERSION_1_8    }}

在android 节点下增加retrolambda :

retrolambda {        javaVersion JavaVersion.VERSION_1_7    }

这是我的添加:

apply plugin: 'com.android.application'apply plugin: 'me.tatarka.retrolambda'android {    compileSdkVersion 23    buildToolsVersion "23.0.2"    defaultConfig {        applicationId "com.dalinbobo.lapa"        minSdkVersion 14        targetSdkVersion 23        versionCode 1        versionName "1.0"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }    compileOptions {        sourceCompatibility JavaVersion.VERSION_1_8        targetCompatibility JavaVersion.VERSION_1_8    }    retrolambda {        javaVersion JavaVersion.VERSION_1_7    }}

最后就可以使用lambda表达式了。

0 0
原创粉丝点击