我尝试在我的代码中使用 Lambda 表达式,但出现此错误:此语言级别不支持 lambda 表达式
我只是在 SO 上搜索它并找到了将其添加到 gradle 文件的解决方案:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
...
jackOptions {
enabled true
}
}
然后我收到一个新错误:错误:无法为 com.android.build.gradle.internal.pipeline.TransformTask 类型的任务“:app:transformJackWithJackForDebug”获取未知属性“classpath”。
再次搜索 SO 发现这是因为我不能同时使用 jack 和 apt...所以我删除了 apt 删除了这些行:
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
...
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
...
}
并且出现了一个新的错误,因为 ButterKnife 需要 apt...
那么如何在同一个项目中使用 Lambda 和 Butterknife 呢?
最佳答案
您应该为 build.gradle
中的 Butter-knife 库使用注释处理器
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
完整的 Gradle 看起来像:
buildscript {
repositories {
....
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'me.tatarka:gradle-retrolambda:3.4.0'
.....
}}
apply plugin: 'me.tatarka.retrolambda'
......
android{
.....
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
}
dependencies {
..........
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}
}
注意:不要使用jackOption = Enabled
关于android - 使用 Lambda 表达式和 Butterknife,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43625279/