2017-04-25 23 views
0

下面是我app.gradle應用插件:「com.android.application」無法在Android Studio中更新到Java 8

apply plugin: 'realm-android' 
android { 
    compileSdkVersion 24 
    buildToolsVersion '25.0.0' 
    defaultConfig { 
     applicationId "com.crayond.vlearning" 
     minSdkVersion 16 
     targetSdkVersion 24 
     versionCode 1 
     versionName "1.0" 
     multiDexEnabled true 
     jackOptions { 
      enabled true 
     } 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 

    compileOptions { 
     incremental false 
     sourceCompatibility JavaVersion.VERSION_1_8 
     targetCompatibility JavaVersion.VERSION_1_8 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile project(':recyclerview') 
    compile 'com.android.support:appcompat-v7:24.2.1' 
    compile 'com.android.support:support-v4:24.2.1' 
    compile 'com.android.support:design:24.2.1' 
    compile 'com.google.android.gms:play-services:10.0.1' 
    compile 'com.google.android.gms:play-services-location:10.0.1' 
    compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:1.5' 
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7' 
    compile 'com.squareup.picasso:picasso:2.5.2' 
    compile 'com.yalantis:phoenix:1.2.3' 
    testCompile 'junit:junit:4.12' 
    /* compile 'com.google.dagger:dagger:2.0' 
    annotationProcessor 'com.google.dagger:dagger-compiler:2.0'*/ 
    annotationProcessor 'org.androidannotations:androidannotations:4.1.0' 
    compile 'org.androidannotations:androidannotations-api:4.1.0' 
} 

我收到以下錯誤,而同步gradle這個: 錯誤:無法獲取用於com.android.build.gradle.internal.pipeline.TransformTask類型的任務'app:transformJackWithJackForDebug'的未知屬性'classpath'。

回答

0

要更新您的Android項目jdk版本爲1.8,請使用retrolambda庫。

在你的應用水平build.gradle文件中加入:

在文件的頂部apply plugin: 'me.tatarka.retrolambda'

2.

android{ 

    //Other stuff 

    compileOptions { 
     targetCompatibility 1.8 
     sourceCompatibility 1.8 
    } 
} 

,然後添加新的依賴到項目層面build.gradle文件。

dependencies { 
    //Other dependencies 
    classpath 'me.tatarka:gradle-retrolambda:3.4.0' 
} 

瞧!現在你可以在你的android項目中使用java 1.8的功能。

+2

這有點誇大其詞。 [retrolambda](https://github.com/orfjackal/retrolambda)將使OP僅支持lambdas和方法引用。這也應該可以通過「官方」Android Studio工具鏈來實現,* Jack *(現已棄用)和[desugar](https://developer.android.com/studio/preview/features/java8-support.html#supported_features) 。當你還需要一些新的Java 8 API(比如Streams)並且同時想要'minSdkVersion <24'時,事情會變得更有趣。如果minSdkVersion是24或更高,我會建議去* desugar *。 –

+0

不知道。感謝您的建議,似乎我應該馬上得到desugar。 –

相關問題