添加java8支持时Android studio错误

时间:2016-08-14 17:12:14

标签: java android android-studio android-jack-and-jill

我的Android Studio或配置有什么问题?

Error:(22, 0) Could not find method jackOptions() for arguments [build_1b0umrzpkhcolzr325bxbizec$_run_closure1$_closure5@41c39fc1] on project ':app' of type org.gradle.api.Project.

这是我的build.gradle

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
    applicationId "com.twtstudio.wepeiyanglite"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
jackOptions {
    enabled true
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}


// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0-beta1'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我想我的开发环境中没有启用插孔,以及如何找出错误并修复它? 我已经安装了jdk1.8

6 个答案:

答案 0 :(得分:32)

jackOptions应该在defaultConfig {}内,如下所示:

defaultConfig {
    ...

    jackOptions {
        enabled true
    }
}

答案 1 :(得分:5)

根据documentation

根据此announcement

不推荐使用Jack工具链。如果您的项目依赖于Jack,则应迁移到使用Android Studio默认工具链中内置的Java 8支持。使用默认工具链还包括对使用Java 8语言功能的第三方库Instant Run以及依赖于中间.class文件的工具的支持。

要禁用Jack并切换到默认工具链,只需从模块的build.gradle文件中删除jackOptions块:

android {
    ...
    defaultConfig {
        ...
        // Remove this block.
        jackOptions {
            enabled true
            ...
        }
    }

    // Keep the following configuration in order to target Java 8.
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

答案 2 :(得分:3)

根据最新文件

defaultConfig {
  ...
  jackOptions {
    enabled true
  }
}

是多余的,所以你可以完全删除它。

请参阅https://developer.android.com/studio/write/java8-support.html?utm_source=android-studio

答案 3 :(得分:0)

如果您不是从jackOptions迁移,请不要添加jackOptions

参考此链接:

https://code.tutsplus.com/tutorials/java-8-for-android-cleaner-code-with-lambda-expressions--cms-29661

答案 4 :(得分:0)

您可以在compileOpitons块之后使用buildTypes,而不必像这样使用jackOptions块:

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.abdo.nadias"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }
}

答案 5 :(得分:-1)

移动:

 jackOptions {
              enabled true
}

default config { }括号内