2017-04-26 33 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}' –