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

时间:2016-03-15 08:36:27

标签: java android gradle android-7.0-nougat

我已对build.gradle进行了更改以升级我的项目,我在MacOSX上使用 Android Studio 2.1预览,这是我的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 Studio抱怨'compileOptions cannot be applied to groovy.lang.closure'

我安装了Android N的工具和SDK,并完全遵循Google's instruction Correct JDK pointed to

编辑:它停止了投诉,但Android可视化设计师提供了以下错误消息:

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

Install a supported JDK

1 个答案:

答案 0 :(得分:0)

对我来说,通过应用上述解决方案并未解决问题。相反,我必须转到Android Studio中的设置并选择“使用gradle包装器”

  

在Android Studio中选择:

文件\设置\构建,执行,部署\构建工具\ Gradle

Mac用户: Android Studio \ Preferences ... \ Build,Execution,Deployment \ Build tools \ Gradle)

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

这删除了所有'无法应用于构建文件中的'(groovy.lang.Closure')警告。

2.单击“文件”,然后选择“使高速缓存无效/重新启动。