Java Android Studio 是否完全支持 JDK 1.8?

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

Is JDK 1.8 fully supported by Android Studio?

javaandroidandroid-studio

提问by Madona Syombua

I just downloaded JDK 1.8.0_51 from my previous JDK 1.8.0_33 because i was having issues. There being some workaround to use Jdk 8 with Android, I was just wondering has Google already added a full support to the JDK in Android studio ? or should I just use JDK 1.7? advice will be highly appreciated.

我刚刚从我之前的 JDK 1.8.0_33 下载了 JDK 1.8.0_51,因为我遇到了问题。有一些在 Android 上使用 Jdk 8 的解决方法,我只是想知道 Google 是否已经在 Android Studio 中添加了对 JDK 的全面支持?还是我应该只使用 JDK 1.7?建议将不胜感激。

采纳答案by d0nut

You should just use JDK 1.7. There are some features in JDK 8 that are not yet supported.

您应该只使用 JDK 1.7。JDK 8 中的某些功能尚不受支持。

回答by Gandalf the Grey

Use Java 1.7 or Java 1.6 I had problems by my self with Android 4 and Java 7 so I used 1.6 and all problems where gone.

使用 Java 1.7 或 Java 1.6 我自己在使用 Android 4 和 Java 7 时遇到了问题,所以我使用了 1.6 并且所有问题都消失了。

I think you will got less problems when you use 1.7 instead of 1.8

我认为当你使用 1.7 而不是 1.8 时你会遇到更少的问题

回答by Shakeeb Ayaz

You can use java 1.8 but dont use 1.8 feature because there are some feature in Java 1.8 which are not supported by now.

您可以使用 Java 1.8 但不要使用 1.8 功能,因为 Java 1.8 中的某些功能目前尚不支持。

回答by ywwynm

Using JDK 1.8 is OK and nothing will bother you except Android Studio may often provide runtime check for you to suggest you using JDK 1.8's feature like lambda. But you can go to Settings->Editor->Inspections->Java language level issues/migration aids and close what you want.

使用 JDK 1.8 没有问题,除了 Android Studio 可能经常为您提供运行时检查以建议您使用 JDK 1.8 的功能(如 lambda)外,没有什么会打扰您。但是您可以转到 Settings->Editor->Inspections->Java 语言级别问题/迁移辅助并关闭您想要的。

回答by Lakhwinder Singh Dhillon

I started getting this error after java update to 1.8

java更新到1.8后我开始收到这个错误

Error:Execution failed for task ':app:processDebugResources'.

错误:任务“:app:processDebugResources”的执行失败。

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\whatever\AppData\Local\Android\sdk\build-tools\23.0.1\aapt.exe'' finished with non-zero exit value 1

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\whatever\AppData\Local\Android\sdk\build-tools\23.0.1\aapt .exe'' 以非零退出值 1 结束

回答by Rakshit Soni

you can now use java8 with android

您现在可以将 java8 与 android 一起使用

add this lines in you build.gradle file

在 build.gradle 文件中添加这一行

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

refer this doc http://developer.android.com/intl/es/preview/j8-Hyman.html

请参阅此文档http://developer.android.com/intl/es/preview/j8-Hyman.html

Make sure to enable Hyman as well with:

确保同时启用 Hyman:

android {
  //...

  defaultConfig {
  //...

  // Required to use Java 8.
  HymanOptions {
    enabled true
  }

}

Additionally, you will need to be using version 24 or greater of the Android SDK Build Tools:

此外,您将需要使用 24 或更高版本的 Android SDK 构建工具:

android {
  //...

  buildToolsVersion "25.0.2"

}

回答by Werner Keil

Actually you get all sorts of crazy Gradle errors when trying to build Android Studio projects with Java 8, like

实际上,在尝试使用 Java 8 构建 Android Studio 项目时,您会遇到各种疯狂的 Gradle 错误,例如

2016-04-10 17:50:49,401 [1624477] WARN - nal.AbstractExternalSystemTask - Gradle 2.10 requires Java 6 or later to run. Your build is currently configured to use Java 5. com.intellij.openapi.externalSystem.model.ExternalSystemException: Gradle 2.10 requires Java 6 or later to run. Your build is currently configured to use Java 5.

2016-04-10 17:50:49,401 [1624477] 警告 - nal.AbstractExternalSystemTask - Gradle 2.10 需要 Java 6 或更高版本才能运行。您的构建当前配置为使用 Java 5。com.intellij.openapi.externalSystem.model.ExternalSystemException:Gradle 2.10 需要 Java 6 或更高版本才能运行。您的构建当前配置为使用 Java 5。

As soon as I switched the default JDK to Java 7 it works fine. Looks like running Android Studio itself with Java SE 8 is tolerated, but building Android apps via Gradle with it only works well with Java 7.

一旦我将默认 JDK 切换到 Java 7,它就可以正常工作。看起来使用 Java SE 8 运行 Android Studio 本身是可以容忍的,但是通过 Gradle 构建 Android 应用程序只适用于 Java 7。

回答by Kreshnik

If you previously used Hyman options, which are deprecated from Android Studio 3.0.0, migrating and using the supported Java 8 language features would be as simple as removing:

如果您之前使用了 Android Studio 3.0.0 中已弃用的 Hyman 选项,则迁移和使用受支持的 Java 8 语言功能就像删除一样简单

HymanOptions { enabled true }

HymanOptions { 启用 true }

from the app's build.gradlefile and keepping the configuration as follows:

来自应用程序的build.gradle文件并保持如下配置:

android {
  ...
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

For details follow thislink.

有关详细信息,请访问链接。