java 添加java8支持时Android工作室错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38944593/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android studio error when add java8 support
提问by life2015
what's wrong with my Android Studio or my config?
我的 Android Studio 或我的配置有什么问题?
Error:(22, 0) Could not find method HymanOptions() for arguments [build_1b0umrzpkhcolzr325bxbizec$_run_closure1$_closure5@41c39fc1] on project ':app' of type org.gradle.api.Project.
and this is my build.gradle
这是我的 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'
}
}
HymanOptions {
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 Hyman is not enabled in my develop enviroment , and how to find out the mistakes and fix it? I have already installed the jdk1.8
我猜我的开发环境中没有启用插孔,如何找出错误并修复它?我已经安装了 jdk1.8
回答by Andrey
HymanOptions should be inside defaultConfig{} like this:
HymanOptions 应该像这样在 defaultConfig{} 中:
defaultConfig {
...
HymanOptions {
enabled true
}
}
回答by Mehrdad Salimi
According to documentation:
根据文档:
The Hyman toolchain is deprecated, as per this announcement. If your project depends on Hyman, 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.
根据本公告,不推荐使用 Hyman 工具链。如果您的项目依赖于 Hyman,您应该迁移到使用 Android Studio 的默认工具链中内置的 Java 8 支持。使用默认工具链还包括对使用 Java 8 语言功能、Instant Run和依赖于中间 .class 文件的工具的第三方库的支持。
To disable Hyman and switch to the default toolchain, simply remove the HymanOptions block from your module's build.gradle file:
要禁用 Hyman 并切换到默认工具链,只需从模块的 build.gradle 文件中删除 HymanOptions 块:
android {
...
defaultConfig {
...
// Remove this block.
HymanOptions {
enabled true
...
}
}
// Keep the following configuration in order to target Java 8.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
回答by AjaiArul
According to latest documentation
根据最新文档
defaultConfig {
...
HymanOptions {
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
请参考https://developer.android.com/studio/write/java8-support.html?utm_source=android-studio
回答by Jay
Do not add HymanOptions
if you are not migrating from HymanOptions
.
不要添加HymanOptions
,如果你不迁移HymanOptions
。
Refere this link:
参考这个链接:
回答by abderazak la3ta3ta
You can use compileOpitons
after buildTypes
block without using HymanOptions
block like this:
您可以compileOpitons
在buildTypes
不使用HymanOptions
块的情况下使用after块,如下所示:
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'
}
}
回答by Prince Ali
move :
移动 :
HymanOptions {
enabled true
}
inside default config { }
parenthesis
内部default config { }
括号