简体   繁体   English

如何在Android Studio 2.3中使用JDK 7?

[英]How to use JDK 7 in Android Studio 2.3?

I want to build a project that required JDK 7, and I tried : navigate to 我想构建一个需要JDK 7的项目,并且尝试了:导航到

File > Project Structure > SDK Location 

and change the path to JDK 7, but an error was appeared please choose JDK 8 or newer 并将路径更改为JDK 7,但出现错误, 请选择JDK 8或更高版本

Is there a way to use JDK 7 in Android Studio 2.3? 有没有办法在Android Studio 2.3中使用JDK 7? Or I should use an older version of Android Studio? 还是我应该使用旧版本的Android Studio?

Edit 编辑

I uninstall all JDK and then install JDK 7, and it's work! 我先卸载所有JDK,然后再安装JDK 7,这样就可以了!

Try to set the java home as correct path in environment variables. 尝试将Java主目录设置为环境变量中的正确路径。 Check your java location in environment variable. 检查环境变量中的Java位置。 Open cmd and type java -version and if it is not java 7 change it in the environment variable. 打开cmd并输入java -version,如果不是Java 7,请在环境变量中对其进行更改。

please check the current version of java in your machine go to terminal and do 请检查计算机中的Java当前版本,然后转到终端并执行

java -version

check if it's 1.7.x 检查是否为1.7.x

use the below command to find java path 使用以下命令查找Java路径

echo $JAVA_HOME

suggestion -Android Studio does not like spaces in the paths to the Android SDK and the JDK. 建议-Android Studio不喜欢Android SDK和JDK路径中的空格。 Installing the JDK in a location that does not contain any spaces allowed to update the location through the Project Structure window. 在不包含任何空格的位置安装JDK,该位置不允许通过“项目结构”窗口更新位置。

In build.gradle : 在build.gradle中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM