在 Android Studio 里面使用 lambda 表达式时, 编译器报错, 然后把 JDK 改成 1.8 版本
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
编译器又报以下错误:
Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8.
这个错误说你必须开启 Jack. 在你的项目中开启支持 Java 8, 你需要配置你的 build.gradle 文件, 就像这样子:
android {
...
compileSdkVersion 23
buildToolsVersion "24rc2"
defaultConfig {
...
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}