Android studio error when add java8 support

2019-06-14 22:30发布

what's wrong with my Android Studio or my config?

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.

and this is my 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
}

I guess the jack is not enabled in my develop enviroment , and how to find out the mistakes and fix it? I have already installed the jdk1.8

6条回答
ゆ 、 Hurt°
2楼-- · 2019-06-14 23:06

According to latest documentation

defaultConfig {
  ...
  jackOptions {
    enabled true
  }
}

is redundant, so you can remove that entirely.

Please refer https://developer.android.com/studio/write/java8-support.html?utm_source=android-studio

查看更多
虎瘦雄心在
3楼-- · 2019-06-14 23:08

According to documentation:

The Jack toolchain is deprecated, as per this announcement. If your project depends on Jack, you should migrate to using Java 8 support built into Android Studio’s default toolchain. Using the default toolchain also includes support for third-party libraries that use Java 8 language features, Instant Run, and tools that depend on intermediate .class files.

To disable Jack and switch to the default toolchain, simply remove the jackOptions block from your module’s build.gradle file:

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
    }
}
查看更多
啃猪蹄的小仙女
4楼-- · 2019-06-14 23:17

Do not add jackOptions if you are not migrating from jackOptions.

Refere this link:

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

查看更多
闹够了就滚
5楼-- · 2019-06-14 23:20

move :

 jackOptions {
              enabled true
}

inside default config { } parenthesis

查看更多
对你真心纯属浪费
6楼-- · 2019-06-14 23:22

You can use compileOpitons after buildTypes block without using jackOptions block like this:

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'
    }
}
查看更多
Bombasti
7楼-- · 2019-06-14 23:25

jackOptions should be inside defaultConfig{} like this:

defaultConfig {
    ...

    jackOptions {
        enabled true
    }
}
查看更多
登录 后发表回答