2017-04-26 60 views
3

我想在我的代码使用Lambda表达式,我得到这个错误:lambda表达式没有在这个语言层面支持使用Lambda表达式和Butterknife

我只是寻找它在SO,发现一个解决方案添加这摇篮文件:

compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_8 
     targetCompatibility JavaVersion.VERSION_1_8 
    } 

defaultConfig { 
     ... 
     jackOptions { 
      enabled true 
     } 
    } 

后来我有一个新的错误:错误:无法获取不明财产“类路径”任务“:应用程序:transformJackWithJackForDebug”型com.android.build.gradle.internal的。 pipeline.TransformTask。

搜查如此反复,发现这是因为我不能在同一时间使用千斤顶和容易...所以我删除容易删除这些行:

apply plugin: 'com.neenbedankt.android-apt' 

dependencies { 
     ... 
     classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' 
     ... 
    } 

,并得到了新的错误,因为黄油刀需要...

那么如何在同一个项目中使用Lambda和Butterknife?

+1

Butterknife 8.5不需要设置'apt'。最近的设置只需要:'compile'c​​om.jakewharton:butterknife:8.4.0' annotationProcessor'com.jakewharton:butterknife-compiler:8.4.0'' –

回答

4

您应该使用注释处理器黄油刀库在build.gradle

compile 'com.jakewharton:butterknife:8.4.0' 
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' 

全部摇篮的样子:

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 =启用

+0

它说我启用杰克:*错误:杰克需要支持java 8语言功能。启用插件或删除sourceCompatibility JavaVersion.VERSION_1_8。* – Laurent

+0

我试图用通常支持Java 8但具有相同问题的最后一次Android Studio预览来打开我的项目。 – Laurent

+0

或者尝试启用'jackOptions {enabled true}' –