AndroidStudio中使用lambda
2016-02-22 11:18
519 查看
在Java8中新增加了对lambda的支持。但是AndroidStudio默认是不支持的。需要借助第三方实现对lambda的支持。
1、在项目的 build.gradle 中添加 classpath 'me.tatarka:gradle-retrolambda:3.2.0' 。加入编译的依赖。
添加后:
2、在app的 build.gradle 中加入plugin声明。 apply plugin: 'me.tatarka.retrolambda' 。
3、 在app的 build.gradle 中加入compileOptions,这会让IDE使用用JAVA8语法解析。
4、指定将源码编译的级别,将代码兼容1.7
最终版:
1、在项目的 build.gradle 中添加 classpath 'me.tatarka:gradle-retrolambda:3.2.0' 。加入编译的依赖。
添加后:
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.5.0' classpath 'me.tatarka:gradle-retrolambda:3.2.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }
2、在app的 build.gradle 中加入plugin声明。 apply plugin: 'me.tatarka.retrolambda' 。
3、 在app的 build.gradle 中加入compileOptions,这会让IDE使用用JAVA8语法解析。
compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }
4、指定将源码编译的级别,将代码兼容1.7
retrolambda { javaVersion JavaVersion.VERSION_1_7 }
最终版:
apply plugin: 'com.android.application' apply plugin: 'me.tatarka.retrolambda' android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "com.xx.xxx" minSdkVersion 15 targetSdkVersion 22 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 } allprojects { gradle.projectsEvaluated { tasks.withType(JavaCompile) { options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" } } } }
相关文章推荐
- Android小知识清单(二)
- Android三种实现Tab界面效果的方法,ViewPager + Fragment
- 如何调试分析Android中发生的tombstone
- Android中onMeasure方法的理解
- Webview实现android简单的浏览器实例代码
- android 获取图片
- Android AIDL使用详解
- ANDROID_MARS学习笔记_S04_005_用sing-post向腾讯微博发一条信息
- Android实现透明度可变的标题栏效果
- android Notification分析——你可能遇到的各种问题
- Android签名详解(转自ok_lanyan - 博客园)
- android开发游记:集成百度定位SDK进行实时定位 获取当前城市地理信息
- Android开发需求功能一览表
- android 5.0 NFC支持
- Android Studio 中 proguard-rules.pro 的模版
- 3种Android隐藏顶部状态栏及标题栏的方法
- Android中,SD卡上的媒体文件(图片、视频)的改变与通知
- Android 标题
- android刷新媒体库
- Android开发-优秀博客参考