18

我的 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

4

6 回答 6

32

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

defaultConfig {
    ...

    jackOptions {
        enabled true
    }
}
于 2016-11-05T22:56:07.517 回答
5

根据文件

根据此公告, 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
    }
}
于 2018-05-23T13:30:37.837 回答
3

根据最新文件

defaultConfig {
  ...
  jackOptions {
    enabled true
  }
}

是多余的,因此您可以完全删除它。

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

于 2018-02-20T05:11:54.480 回答
1

您可以使用compileOpitonsafterbuildTypes块而不使用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'
    }
}
于 2019-02-09T09:29:17.280 回答
0

移动 :

 jackOptions {
              enabled true
}

default config { }括号内

于 2018-04-24T07:26:45.610 回答
0

jackOptions如果您不是从jackOptions.

参考这个链接:

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

于 2018-04-16T04:24:40.233 回答