使用 java 8 在 Android Studio 2.1 中出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37024263/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 02:07:29  来源:igfitidea点击:

Getting error in Android Studio 2.1 with java 8

javaandroidandroid-studiogradlejava-8

提问by Soham

Currently I am using java 8with latest android studio 2.1

目前我正在使用java 8最新的android studio 2.1

Here is my build.gradlefile

这是我的build.gradle文件

android {
    compileSdkVersion 22
    buildToolsVersion "24rc3"

    defaultConfig {
        applicationId "com.name"
        minSdkVersion 10
        targetSdkVersion 19
        HymanOptions {
            enabled true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
.......
}

I am getting the below compile time error that I have no clue

我收到以下编译时错误,我不知道

Error:com.android.Hyman.frontend.FrontendCompilationException: Failed to compile at com.android.Hyman.Hyman.buildSession(Hyman.java:892) at com.android.Hyman.Hyman.run(Hyman.java:472) at com.android.Hyman.api.v01.impl.Api01ConfigImpl$Api01CompilationTaskImpl.run(Api01ConfigImpl.java:102) ... 8 more Warning:Exception while processing task java.io.IOException: com.android.Hyman.api.v01.CompilationException: Failed to compile :oTT:compileDebugJavaWithHyman FAILED Error:Execution failed for task ':oTT:compileDebugJavaWithHyman'.

java.io.IOException: com.android.Hyman.api.v01.CompilationException: Failed to compile Information:BUILD FAILED

错误:com.android.Hyman.frontend.FrontendCompilationException:无法在 com.android.Hyman.Hyman.buildSession(Hyman.java:892) at com.android.Hyman.Hyman.run(Hyman.java:472) 处编译com.android.Hyman.api.v01.impl.Api01ConfigImpl$Api01CompilationTaskImpl.run(Api01ConfigImpl.java:102) ... 8 more Warning:Exception while processing task java.io.IOException: com.android.Hyman.api.v01 .CompilationException:无法编译:oTT:compileDebugJavaWithHyman FAILED 错误:任务“:oTT:compileDebugJavaWithHyman”的执行失败。

java.io.IOException:com.android.Hyman.api.v01.CompilationException:编译失败信息:BUILD FAILED

Please feel to ask if you need some details.

请随意询问您是否需要一些详细信息。

回答by Noah Ternullo

I had this error too, and what I found was that the error itself was masking another compilation issue. Look at your Console Messages carefully and see if there is something else not compiling. Once I solved the underlying issue with my own code, this error magically disappeared. Hope this helps.

我也有这个错误,我发现错误本身掩盖了另一个编译问题。仔细查看您的控制台消息,看看是否还有其他未编译的内容。一旦我用自己的代码解决了潜在的问题,这个错误就神奇地消失了。希望这可以帮助。

回答by Alex Evtushik

Try to use next values:

尝试使用下一个值:

compileSdkVersion = "android-N"
buildToolsVersion = "24.0.0 rc3"

回答by Angel Koh

you can try

你可以试试

compileSdkVersion 23
buildToolsVersion '24.0.0-rc3'

note the dash before rc3. This is according to http://developer.android.com/preview/setup-sdk.htmlunder the section "Update an existing project"

注意rc3之前的破折号。这是根据“更新现有项目”部分下的http://developer.android.com/preview/setup-sdk.html

I am using 23 just for the lambda.

我仅将 23 用于 lambda。

the following link shows the Supported Java 8 Language Features and APIs https://developer.android.com/preview/j8-Hyman.html

以下链接显示了支持的 Java 8 语言功能和 API https://developer.android.com/preview/j8-Hyman.html

回答by Alex.F

I think we are all looking mostly at the same answer. To be precise I'd say "make sure the buildToolsVersion = "[version]"is the sameas the [version]in the error".
For some this will be 24.0.0

我认为我们都在关注相同的答案。准确地说我想说“确保buildToolsVersion = "[version]"相同[version]错误。”
对于某些人来说,这将是24.0.0

回答by JingYaoChen

Some java 8 features only support Android N. read android docs http://developer.android.com/preview/j8-Hyman.html#configuration

某些 java 8 功能仅支持 Android N。阅读 android 文档 http://developer.android.com/preview/j8-Hyman.html#configuration

When I use Default Methods on sdk23, I got this error too. so update your sdk version to Android N.

当我在 sdk23 上使用默认方法时,我也遇到了这个错误。所以将您的 sdk 版本更新为 Android N。