一:只需要支持Lambda表达式

在app/build.gradle下添加

android {    //设置JDK1.8    compileOptions {            sourceCompatibility JavaVersion.VERSION_1_8            targetCompatibility JavaVersion.VERSION_1_8        }}buildscript {    repositories {        mavenCentral()    }    dependencies {        classpath 'me.tatarka:gradle-retrolambda:3.2.5'    }}repositories {    mavenCentral()}//添加插件apply plugin: 'me.tatarka.retrolambda'

然后就可以使用Lambda表达式了,比如

new Thread(new Runnable() {    public void run() {      System.out.println("Run!");    }  }).start();

可以简化成

new Thread(() ->System.out.println("Run!")).start();

二:Java 8和Jack编译

参考Android官网

android {  ...  defaultConfig {    ...    jackOptions {      enabled true    }  }  compileOptions {    sourceCompatibility JavaVersion.VERSION_1_8    targetCompatibility JavaVersion.VERSION_1_8  }}

注意: 需要使用Android N 也就是API24,以下是官方原话:

To start using these features, you need to download and set up Android Studio 2.1 and the Android N Preview SDK, which includes the required Jack toolchain and updated Android Plugin for Gradle. If you haven’t yet installed the Android N Preview SDK, see Set Up to Develop for Android N.

开启jack编译后,不能使用apt插件,报异常:Error:Could not find property ‘options’ on task ‘:app:compileDebugJavaWithJack’.参考:google issues

补充

可以使用annotationProcessor代替apt插件,之后即可使用jack编译
官方原文

更多相关文章

  1. Android(安卓)Studio 编译 ApiDemos
  2. Android(安卓)studio3.1.2 坑——3rd-party Gradle plug-ins may
  3. Android(安卓)编译环境下常用命令
  4. 如何打造稳定、好用的 Android(安卓)LayoutInspector?
  5. android binder c++层-客户端(c++) 调用 服务端(c++) 例子
  6. Android原生(Native)C开发之一 环境搭建篇
  7. Android之NDK开发
  8. ubuntu下使用nginx和nginx-rtmp-module配置直播推流服务器
  9. Android高版本P/Q/R源码编译指南

随机推荐

  1. ActivityManager: Starting: Intent { ac
  2. Android(安卓)DatePicker 使用示例
  3. android 上传Bitmap到服务器端
  4. 拍照或从图库选择
  5. Android(安卓)Studio3.0 Annotation proc
  6. 手机安全卫士开发系列(5)——自动更新
  7. setonClickListener()的解释
  8. Android(安卓)Lesson Two: Ambient and D
  9. Android(安卓)studio 安卓填写注册表单源
  10. Android(安卓)开启关闭软键盘