升级 Android 项目以使用 Java8(compileOptions 不能应用于 groovy.lang.closure)

Upgrading Android project to use Java8 (compileOptions cannot be applied to groovy.lang.closure)

我已经对 build.gradle 进行了更改以升级我的项目,我正在使用 Android Studio 2.1 Preview on MacOSX,这是我的 Gradle:

build.gradle.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-N'
    buildToolsVersion '24.0.0 rc1'

    defaultConfig {
        applicationId "com.xxx.xxx"
        minSdkVersion 21
        targetSdkVersion 'N'
        versionCode 1
        versionName "1.0"
        jackOptions {
            enabled true
        }

    }
    compileOptions {
            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(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.0.0-alpha1'
    compile 'com.android.support:design:24.0.0-alpha1'
    compile 'com.android.support:support-v4:24.0.0-alpha1'
    compile 'com.android.support:cardview-v7:24.0.0-alpha1'
    compile 'com.android.support:recyclerview-v7:24.0.0-alpha1'
}

Android 工作室抱怨 'compileOptions cannot be applied to groovy.lang.closure'

我安装了AndroidN的工具和SDK,完全按照Google's instruction

编辑:它停止了抱怨,但是 Android 视觉设计师给出了以下错误信息:

Android N requires the IDE to be running with Java 1.8 or later

Install a supported JDK

对我来说,应用上述解决方案并没有解决问题。相反,我必须转到 Android Studio 和 select "Use gradle wrapper":

中的设置

In Android Studio select:

File\Settings\Build, 执行, Deployment\Build tools\Gradle

(Mac 用户: Android Studio\Preferences...\构建, 执行, Deployment\Build tools\Gradle )

标记:使用默认 gradle 包装器(默认)

这删除了构建文件中的所有 'cannot be applied to '(groovy.lang.Closure') 警告。

2.Click "File" 然后 select “使缓存无效/重新启动。