“Android 创建”调用在 Windows 7 中失败 - 缺少 JDK
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3052743/
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 Create" call fails in windows 7 - missing JDK
提问by reuscam
I'm having a problem getting my android dev environment setup in Windows 7. I follow the instructions here,as well as several environment sublinks. I am using Eclipse with the Android plugin. I have installed the Java JDK several times, in various locations (jdk-6u20-windows-i586.exe) - but I am obviously missing something.
我在 Windows 7 中设置我的 android 开发环境时遇到问题。我按照此处的说明以及几个环境子链接进行操作。我正在使用带有 Android 插件的 Eclipse。我已经在不同的位置(jdk-6u20-windows-i586.exe)多次安装了 Java JDK - 但我显然遗漏了一些东西。
Every time I run "android create avd --target 2 --name my_avd" I get an error:
每次运行“android create avd --target 2 --name my_avd”时,都会出现错误:
C:\Users\andrew>android create avd --target 2 --name my_avd
WARNING: Java not found in your path.
Checking it it's installed in C:\Program Files\Java instead.
ERROR: No suitable Java found. In order to properly use the Android Developer
Tools, you need a suitable version of Java installed on your system. We
recommend that you install the JDK version of JavaSE, available here:
http://java.sun.com/javase/downloads/
You can find the complete Android SDK requirements here:
http://developer.android.com/sdk/requirements.html
This error message is the reason for me installing the JDK several times over. First I tried installing to a location on my e: drive. I then moved it to the default loc (program files (x86)\java\jdk.6.something. I also tried forcing it to go into the program files\ path, but it still automatically installs into the (x86) path. I have added the install path to my path environment variable every single time, yet I still continue to get this error. My suspicion is that windows 7 and the android tools are not playing together well in terms of finding the JDK, but who knows, it may be something entirely different. If you have seen this error before, I would appreciate a hint.
此错误消息是我多次安装 JDK 的原因。首先,我尝试安装到我的 e: 驱动器上的某个位置。然后我将它移动到默认的 loc (program files (x86)\java\jdk.6.something。我也尝试强制它进入 program files\ 路径,但它仍然自动安装到 (x86) 路径中。我每次都将安装路径添加到我的路径环境变量中,但我仍然继续收到此错误。我怀疑 Windows 7 和 android 工具在查找 JDK 方面不能很好地协同工作,但谁知道呢?可能完全不同。如果您以前见过此错误,我将不胜感激。
采纳答案by Dave Webb
The android
command is just a Windows Batch file which in turn uses the batch file tools\lib\find_java.bat
to find Java.
该android
命令只是一个 Windows 批处理文件,它反过来使用批处理文件tools\lib\find_java.bat
来查找 Java。
Having a look at the source, it does the following:
查看源代码,它执行以下操作:
- Looks to see if
java.exe
is on yourPATH
. - Looks for
java.exe
in somewhere under%ProgramFiles%
- 看看是否
java.exe
在您的PATH
. java.exe
在下某处寻找%ProgramFiles%
Your problem arises because you're using the a 64-bit version of Windows. This means %ProgramFiles%
is C:\Program Files
but Java is installed in C:\Program Files (x86)
as it's a 32-bit application, meaning find_java.bat
doesn't find it.
您的问题出现是因为您使用的是 64 位版本的 Windows。这意味着 %ProgramFiles%
是C:\Program Files
但安装了 Java,C:\Program Files (x86)
因为它是一个 32 位应用程序,这意味着find_java.bat
找不到它。
So to fix this you'll need to add the directory containing java.exe
to your PATH environment variable.
因此,要解决此问题,您需要将包含的目录添加java.exe
到 PATH 环境变量中。
You'll need to the add the directory containing java.exe
- something like C:\Program Files (x86)\Java\jdk6\bin
- on to the end of PATH
with a semicolon in front of it to separate it from the previous entry.
您需要将包含java.exe
- 类似C:\Program Files (x86)\Java\jdk6\bin
-的目录添加到末尾,PATH
并在其前面使用分号将其与上一个条目分开。
This question on superuser.comcovers maintaining Environment Variables in Windows 7.
superuser.com 上的这个问题涵盖了在 Windows 7 中维护环境变量。
回答by Eric
I had this same problem, after accidentally installed the 32-bit version of Java SDK. I uninstalled it and installed the 64-bit version (since I'm using Windows 7 64). The Android SDK setup never found Java correctly, even after I added it to my PATH variable!
在不小心安装了 32 位版本的 Java SDK 后,我遇到了同样的问题。我卸载了它并安装了 64 位版本(因为我使用的是 Windows 7 64)。Android SDK 设置从未正确找到 Java,即使我将它添加到我的 PATH 变量之后!
After a bit of digging around, I discovered a java.exe floating around in my system32 folder, which in the order of the PATH variable came before my SDK path. After whacking the java.exe in my system32 folder, the Android Setup ran just fine!
经过一番挖掘,我发现在我的 system32 文件夹中漂浮着一个 java.exe,它按照 PATH 变量的顺序出现在我的 SDK 路径之前。在我的 system32 文件夹中重击 java.exe 后,Android 安装程序运行得很好!
Hope this helps.
希望这可以帮助。
回答by kuncevic.dev
It is really hell with JDK detection...
JDK检测真的很糟糕......
My params: Win 7 x64 + JDK x64 (JDK path (c:\Program Files\Java\jre7\bin)
我的参数:Win 7 x64 + JDK x64(JDK 路径 (c:\Program Files\Java\jre7\bin)
Was googling and playing around with env variables may be 1 hour - no way.
在谷歌上搜索并使用 env 变量可能需要 1 小时 - 没办法。
Finally come with such solution
终于有了这样的解决方案
Manually edit android-sdk-windows\tools\lib\find_java.bat
by hardcoding the path to java.exe
android-sdk-windows\tools\lib\find_java.bat
通过硬编码 java.exe 的路径手动编辑
set java_exe=c:\Progra~1\Java\jre7\bin\java.exe
if not defined java_exe goto :CheckFailed
:SearchJavaW
set javaw_exe=c:\Progra~1\Java\jre7\bin\javaw.exe
if not exist %javaw_exe% set javaw_exe=%java_exe%
goto :EOF
Thats works for me.
那对我有用。
回答by Arturo
In the SDK tools folder go to libs and edit find_java.bat
. It can usually be found in C:\Program Files (x86)\Android\android-sdk-windows\tools\lib
.
在 SDK 工具文件夹中,转到 libs 并编辑find_java.bat
. 它通常可以在C:\Program Files (x86)\Android\android-sdk-windows\tools\lib
.
Change all instances of %PROGRAMFILES%
to %PROGRAMFILES(X86)%
.
将 的所有实例更改%PROGRAMFILES%
为%PROGRAMFILES(X86)%
。
I did this and the error went away.
我这样做了,错误就消失了。
回答by SeaSun
Find android-sdk-windows\tools\lib\find_java.bat
and add something like the following:
查找android-sdk-windows\tools\lib\find_java.bat
并添加如下内容:
set java_exe=
call :TestJavaDir "%JAVA_HOME%"
if defined java_exe goto :EOF
回答by Will Tartak
What worked for me was this:
对我有用的是:
add a path to your java/bin directory to the system Path variable. Do NOT include java.exe.
将 java/bin 目录的路径添加到系统 Path 变量中。不要包含 java.exe。
Steps on Win 7 64bit:
Win 7 64位的步骤:
- Click Windows Button
- Right Click on Computer
- Select Properties from the Context Menu
- Click Advanced System Settings on the top left section
- Click the Environment Variables... button at the bottom of the properties dialog
- On the bottom list (System variables) find the "Path" variable
- Click the Edit button
- Go to the end of the textbox and type something like c:\program files\java\jdk1.6.0_26\bin (make sure it matches the name of your java directory!)
- Click OK
- Click OK
- Click OK
- 单击窗口按钮
- 右键单击计算机
- 从上下文菜单中选择属性
- 单击左上角的高级系统设置
- 单击属性对话框底部的环境变量...按钮
- 在底部列表(系统变量)中找到“路径”变量
- 单击编辑按钮
- 转到文本框的末尾并键入类似 c:\program files\java\jdk1.6.0_26\bin 的内容(确保它与您的 java 目录的名称匹配!)
- 单击确定
- 单击确定
- 单击确定
Try it out!
试试看!
hth,
嗯,
\ ^ / i l l
\ ^ / 生病了
回答by anon12345
I put rem statement in android.bat after the call command and hardcode the path of \bin\java.exe:
我将 rem 语句放在 android.bat 中的 call 命令之后,并对 \bin\java.exe 的路径进行硬编码:
rem Check we have a valid Java.exe in the path.
set java_exe=<..>\jdk1.6.0_31\bin\java.exe
rem call lib\find_java.bat
if not defined java_exe goto :EOF
Same for setting other variable javaw_exe thus:
设置其他变量 javaw_exe 也是如此:
set javaw_exe=<..>\jre1.6.0_31\bin\javaw.exe
if not exist %javaw_exe% set javaw_exe=%java_exe%
goto :EOF
回答by Buurman
C:\Windows\SysWOW64
C:\Windows\SysWOW64
1down vote
1票反对
I also had this same problem -> accidentally installed the 32-bit version of Java SDK -> uninstalled -> installed the 64-bit version (Windows 7 64) -> -> the Android SDK setup never found Java correctly!
我也遇到了同样的问题 -> 不小心安装了 32 位版本的 Java SDK -> 卸载 -> 安装了 64 位版本(Windows 7 64) -> -> Android SDK 安装程序从未正确找到 Java!
I discovered a java.exe floating around in C:\Windows\SysWOW64 folder. After renaming this java.exe to javaX.exe, the Android Setup ran just fine!
我发现一个 java.exe 漂浮在 C:\Windows\SysWOW64 文件夹中。将此 java.exe 重命名为 javaX.exe 后,Android 安装程序运行良好!