【问题标题】:Android studio error when add java8 support添加 java8 支持时出现 Android Studio 错误
【发布时间】:2023-03-18 05:50:01
【问题描述】:

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

【问题讨论】:

  • 在你的 defaultConfig 和 Sync 项目中移动 jackOptions
  • 我按照你的提示编辑了 apt 和 classpath 设置,它有效,谢谢!

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


【解决方案1】:

移动:

 jackOptions {
              enabled true
}

default config { }括号内

【讨论】:

    【解决方案2】:

    您可以在buildTypes 块之后使用compileOpitons,而无需像这样使用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'
        }
    }
    

    【讨论】:

      【解决方案3】:

      根据documentation

      Jack 工具链已被弃用,根据 announcement。如果您的项目依赖于 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
          }
      }
      

      【讨论】:

        【解决方案4】:

        根据最新文档

        defaultConfig {
          ...
          jackOptions {
            enabled true
          }
        }
        

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

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

        【讨论】:

          【解决方案5】:

          jackOptions 应该像这样在 defaultConfig{} 中:

          defaultConfig {
              ...
          
              jackOptions {
                  enabled true
              }
          }
          

          【讨论】:

            【解决方案6】:

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

            参考这个链接:

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

            【讨论】:

              猜你喜欢
              • 2014-04-28
              • 2014-05-06
              • 2019-08-03
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2015-03-31
              相关资源
              最近更新 更多