Java Windows 7 上的 Android Studio 安装失败,找不到 JDK

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

Android Studio installation on Windows 7 fails, no JDK found

androidinstallationjavaandroid-studio

提问by Jaison Brooks

I downloaded Android Studio and attempted to launch the program.

我下载了 Android Studio 并尝试启动该程序。

This is running on Windows 7 64-bit with Java 1.7. During the installation my Java 1.7 is detected, and the rest of the installation goes through just fine. However, when attempting to launch the application from the desktop icon, nothing happens. Looking at the task manager, a new process from the CMD is loaded. This is because it's attempting to run the batch file studio.bat.

这是在带有 Java 1.7 的 Windows 7 64 位上运行。在安装过程中检测到我的 Java 1.7,其余的安装过程都很好。但是,当尝试从桌面图标启动应用程序时,没有任何反应。查看任务管理器,从 CMD 加载了一个新进程。这是因为它正在尝试运行批处理文件studio.bat

When I execute via CMD, I get the following error:

当我通过 CMD 执行时,出现以下错误:

ERROR: cannot start Android Studio. No JDK found. Please validate either ANDROID_STUDIO_JDK, or JDK_HOME or JAVA_HOME points to valid JDK installation. ECHO is off. Press any key to continue . . .

错误:无法启动 Android Studio。未找到 JDK。请验证 ANDROID_STUDIO_JDK、JDK_HOME 或 JAVA_HOME 指向有效的 JDK 安装。ECHO 关闭。按任意键继续 。. .

I've attempted to open the ideaproperties file to see if there was something I could configure for this ANDROID_STUDIO_JDKor something like that. However, I found nothing. I hope some of you can let me know if you were able to install this or if you are having problems as well.

我试图打开idea属性文件,看看是否有我可以配置的ANDROID_STUDIO_JDK东西或类似的东西。然而,我什么也没找到。我希望你们中的一些人可以让我知道你是否能够安装它或者你是否也遇到了问题。

采纳答案by Evgheni Ponomarenco

Adding a system variable JDK_HOMEwith value c:\Program Files\Java\jdk1.7.0_21\worked for me. The latest Java release can be downloaded here.

添加JDK_HOME具有值的系统变量c:\Program Files\Java\jdk1.7.0_21\对我有用。可以在此处下载最新的 Java 版本。

Additionally, make sure the variable JAVA_HOMEis also set with the above location.

此外,请确保变量JAVA_HOME也设置为上述位置。

回答by Jay Mayu

OK, I figured out how fix this nasty bug.

好的,我想出了如何修复这个讨厌的错误。

Before you start

在你开始之前

Go to your Android Studio installation folder and locate the bin folder. Inside the bin folder, you will find studio.bat. Execute the file, and it'll show the error. If it is about the Java path then follow the tip 1.

转到您的 Android Studio 安装文件夹并找到 bin 文件夹。在 bin 文件夹中,您会找到studio.bat。执行文件,它会显示错误。如果是关于 Java 路径,则按照提示 1。

Tip 1

提示 1

When you set the path JAVA_HOME, etc., make sure not to include binat the end of the path. This solved the issue for me.

设置路径JAVA_HOME等时,请确保不要包含bin在路径的末尾。这为我解决了这个问题。

JAVA_HOME=> C:\Program Files\Java\jdk1.7.0_21

JAVA_HOME=> C:\Program Files\Java\jdk1.7.0_21

path=> C:\Program Files\Java\jdk1.7.0_21\bin

path=> C:\Program Files\Java\jdk1.7.0_21\bin

It works fine with JDK 1.7 (I tried with 32 bit).

它适用于 JDK 1.7(我尝试使用 32 位)。

If you do so, you can see the initial screen as below.

如果这样做,您可以看到如下所示的初始屏幕。

Enter image description here

在此处输入图片说明

Tip 2

提示 2

Are you getting the below error message?

您是否收到以下错误消息?

Your Android SDK is out of date or is missing templates. Please ensure you are using SDK version 22 or later.

您的 Android SDK 已过期或缺少模板。请确保您使用的是 SDK 版本 22 或更高版本。

This error probably occurs, because you have reference to your older SDK (that you downloaded with Eclipse) in your path variable. Go to Environment variables and remove any reference to the old SDK folder and point it to new SDK folder that is found inside the Android Studio installation folder.

可能会发生此错误,因为您在路径变量中引用了较旧的 SDK(使用Eclipse下载)。转到环境变量并删除对旧 SDK 文件夹的任何引用,并将其指向 Android Studio 安装文件夹中的新 SDK 文件夹。

Save and restart Studio, things should work as expected now.

保存并重新启动 Studio,现在应该可以正常工作了。

Tip 3

提示 3

If you hate messing around with the path variable as given above by removing old references, simply follow the following steps to refer to new SDK path that comes with Studio.

如果您讨厌通过删除旧引用来处理上面给出的路径变量,只需按照以下步骤引用 Studio 附带的新 SDK 路径。

*Project Defaults* -> *Project Structure* -> Click "New" -> Select "Android SDK" -> Select the SDKfolder inside the studio installation.

*Project Defaults* -> *Project Structure* -> Click "New" -> Select "Android SDK" -> Select the SDKStudio 安装中的文件夹。

回答by Oleg Kislitsyn

If you are getting message "Your Android SDK is out of date…" — click "Configure" —> "Project Defaults" —> "Project Structure", pick "SDKs" —> "Android SDK" and in a "Build Target" choose "Android 4.2.2". Click "OK". Now it should work fine.

如果您收到消息“您的 Android SDK 已过期...”—单击“配置”—>“项目默认值”—>“项目结构”,选择“ SDK”—>“ Android SDK”并在“构建目标”中选择“ Android 4.2.2”。单击“确定”。现在它应该可以正常工作。

回答by Vainilla

I had the same issue. I got resolved setting up correctly the environment variables in windows, for instance:

我遇到过同样的问题。我解决了在 Windows 中正确设置环境变量的问题,例如:

JAVA_HOME -> C:\Program Files\Java\jdk1.6.0_45
path -> C:\Program Files\Java\jdk1.6.0_45\bin

回答by Daniel Imms

My issue was caused because I have an &character in my Windows user name, so when installed in the default path I was getting the following error after running bin/studio.bat

我的问题是因为我的&Windows 用户名中有一个字符,所以当安装在默认路径中时,我在运行后收到以下错误bin/studio.bat

                                               |
                                               v notice broken path
The system cannot find the file C:\Users\Daniel \studio64.exe.vmoptions.
Exception in thread "main" java.lang.NoClassDefFoundError: com/intellij/idea/Main
Caused by: java.lang.ClassNotFoundException: com.intellij.idea.Main
        at java.net.URLClassLoader.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: com.intellij.idea.Main.  Program will exit.

So I uninstalled and reinstalled it to program files and it launches fine now.

因此,我将其卸载并重新安装到程序文件中,现在它可以正常启动。

回答by Sagar Maiyad

Install the latest JDKin your system from JDK 7 and JRE 7 Installation Guide.

JDK 7 和 JRE 7 安装指南在您的系统中安装最新的JDK

JAVA_HOME -> C:\Program Files\Java\jdk1.7.0_4
path -> C:\Program Files\Java\jdk1.7.0_4\bin

回答by Lam Do

I got the problem that the installation stopped by "$(^name) has stopped working" error. I have installed Java SE Development kit already, also set both SDK_HOME and JAVA_HOME that point to "C:\Program Files\Java\jdk1.7.0_21\"

我遇到了安装因“ $(^name) 已停止工作”错误而停止的问题。我已经安装了 Java SE 开发工具包,还将 SDK_HOME 和 JAVA_HOME 都设置为指向“C:\Program Files\Java\jdk1.7.0_21\”

My laptop installed with Windows 7 64 bits

我的笔记本电脑安装了 Windows 7 64 位

So I tried to install the 32 bit version of Java SE Developement kit, set my JAVA_HOME to "C:\Program Files (x86)\Java\jdk1.7.0_21", restart and the installation worked OK.

所以我尝试安装 32 位版本的 Java SE 开发工具包,将我的 JAVA_HOME 设置为“C:\Program Files (x86)\Java\jdk1.7.0_21”,重新启动,安装工作正常。

回答by scone

In my experience, I was unable (even after adding JDK_HOME) to launch Studio via either the shortcut or studio.exe itself. I had to first run bin/studio.bat (mentioned in the original question). After the first successful launch, I'm able to start it by the shortcut.

根据我的经验,我无法(即使在添加 JDK_HOME 之后)通过快捷方式或 studio.exe 本身启动 Studio。我必须先运行 bin/studio.bat (在原始问题中提到)。第一次成功启动后,我可以通过快捷方式启动它。

回答by AndroidPenguin

If you have a 64 bit windows OS, pointing the JAVA_HOME system variable to

如果您有 64 位 Windows 操作系统,请将 JAVA_HOME 系统变量指向

C:\Program Files (x86)\Java\jdk1.7.0_21

Will work when

将工作时

C:\Program Files\Java\jdk1.7.0_21

fails to work.

无法工作。

回答by Der Hochstapler

I couldn't get this to work no matter which environment variables I set. So I simply put a copy of the JDK into my Android Studio installation folder.

无论我设置了哪些环境变量,我都无法让它发挥作用。所以我只是将 JDK 的副本放入我的 Android Studio 安装文件夹中。

  1. Copy the contents of the JDK installation (for example, C:\Program Files (x86)\Java\jdk1.7.0_21)

  2. Paste them into the installation directory of the Android Studio (for example, C:\Program Files (x86)\Android\android-studio)

  1. 复制JDK安装的内容(例如,C:\Program Files (x86)\Java\jdk1.7.0_21

  2. 将它们粘贴到 Android Studio 的安装目录中(例如,C:\Program Files (x86)\Android\android-studio

I somewhat assumed that the issue was caused by having the x64 version of the JDK installed. But what was especially confusing was the fact that I could start Android Studio just fine when I started the studio.batas an Administrator (even though the environment variables were set for my personal user account).

我有点假设这个问题是由安装了 x64 版本的 JDK 引起的。但特别令人困惑的是,当我studio.bat以管理员身份启动时,我可以很好地启动 Android Studio (即使为我的个人用户帐户设置了环境变量)。

studio.batwill look for several valid options when determining which JDK to use.

studio.bat在确定使用哪个 JDK 时,将寻找几个有效的选项。

:: Locate a JDK installation directory which will be used to run the IDE.:: Try (in order): ANDROID_STUDIO_JDK, ..\jre, JDK_HOME, JAVA_HOME.

:: Locate a JDK installation directory which will be used to run the IDE.:: Try (in order): ANDROID_STUDIO_JDK, ..\jre, JDK_HOME, JAVA_HOME.

As explained above, I picked the ..\jreoption.

如上所述,我选择了该..\jre选项。