Android SDK 和 AVD 管理器将无法运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11023179/
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 SDK and AVD Manager will not run
提问by lopsided98
I installed the Android SDK but I cannot use it because the AVD and SDK Managers do not run. When I try to open either one of them, a command prompt window pops up for about a half a second and then closes. I have tried running the exe from the command prompt to see if there was an error message but there is no output and it acts the same. I researched the problem and found out that the exact same thing happens to other computers. I tried some of the solutions that were posted there:
我安装了 Android SDK,但我无法使用它,因为 AVD 和 SDK 管理器没有运行。当我尝试打开其中任何一个时,命令提示符窗口会弹出大约半秒然后关闭。我尝试从命令提示符运行 exe 以查看是否有错误消息,但没有输出并且它的行为相同。我研究了这个问题,发现其他计算机也发生了完全相同的事情。我尝试了那里发布的一些解决方案:
Solutions that didn't seem to work
似乎不起作用的解决方案
- Adding the JDK location to the beginning of the
PATH
environment variable - Adding the Android SDK location to the
PATH
environment variable - Running the applications as an administrator
- Deleting the
.android
folder from the user (C:/Users/[User Name]
) directory - Installing in the root of the
C:
drive, instead of in Program Files
- 将 JDK 位置添加到
PATH
环境变量的开头 - 将 Android SDK 位置添加到
PATH
环境变量中 - 以管理员身份运行应用程序
.android
从用户 (C:/Users/[User Name]
) 目录中删除文件夹- 安装在
C:
驱动器的根目录中,而不是在程序文件中
OS Info: Windows 7 Home Premium, Admin Privileges
操作系统信息:Windows 7 家庭高级版、管理员权限
Update
更新
I think I found the source of the problem, but I still don't know how to fix it. The problem seems to be with my android.bat
file in the C:\Android\android-sdk\tools
directory. It tries to call find_java.bat
but is unable to because of a small syntax problem. This is the output:
我想我找到了问题的根源,但我仍然不知道如何解决它。问题似乎出在我android.bat
的C:\Android\android-sdk\tools
目录中的文件上。它尝试调用find_java.bat
但由于一个小的语法问题而无法调用。这是输出:
'C:\Android\ANDROI~1\tools\lib\find_java.exe -s' is not recognized as an internal or external command, operable program or batch file.
'C:\Android\ANDROI~1\tools\lib\find_java.exe -s' 不是内部或外部命令,也不是可运行的程序或批处理文件。
ERROR: No suitable Java found. In order to properly use the Android Developer Tools, you need a suitable version of Java JDK installed on your system. We recommend that you install the JDK version of JavaSE, available here: http://www.oracle.com/technetwork/java/javase/downloads
错误:未找到合适的 Java。为了正确使用 Android 开发者工具,您需要在您的系统上安装合适版本的 Java JDK。我们建议您安装 JavaSE 的 JDK 版本,可在此处获得:http: //www.oracle.com/technetwork/java/javase/downloads
You can find the complete Android SDK requirements here: http://developer.android.com/sdk/requirements.html
您可以在此处找到完整的 Android SDK 要求:http: //developer.android.com/sdk/requirements.html
After some modifications to android.bat
, I was able to get it to call find_java.bat
, which in turn got a bunch of errors no matter what I did to it. I finally got frustrated and decided to hard-code in the location of java.exe
. Later on in the batch file there was still another error. I am starting to think that something is really wrong with my installation or the batch file. This is the batch file (android.bat
):
对 进行了一些修改后android.bat
,我能够让它调用find_java.bat
,无论我对它做什么,都会产生一堆错误。我终于感到沮丧,并决定在java.exe
. 后来在批处理文件中还有另一个错误。我开始认为我的安装或批处理文件确实有问题。这是批处理文件 ( android.bat
):
@echo off
rem Copyright (C) 2007 The Android Open Source Project
rem
rem Licensed under the Apache License, Version 2.0 (the "License");
rem you may not use this file except in compliance with the License.
rem You may obtain a copy of the License at
rem
rem http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.
rem Useful links:
rem Command-line reference:
rem http://technet.microsoft.com/en-us/library/bb490890.aspx
rem don't modify the caller's environment
setlocal
rem Set up prog to be the path of this script, including following symlinks,
rem and set up progdir to be the fully-qualified pathname of its directory.
set prog=%~f0
rem Grab current directory before we change it
set work_dir="%cd%"
rem Change current directory and drive to where the script is, to avoid
rem issues with directories containing whitespaces.
cd /d %~dp0
rem Check we have a valid Java.exe in the path.
set java_exe=
call lib\find_java.bat
if not defined java_exe goto :EOF
set jar_path=lib\sdkmanager.jar;lib\swtmenubar.jar
rem Set SWT.Jar path based on current architecture (x86 or x86_64)
for /f %%a in ('%java_exe% -jar lib\archquery.jar') do set swt_path=lib\%%a
:MkTempCopy
rem Copy android.bat and its required libs to a temp dir.
rem This avoids locking the tool dir in case the user is trying to update it.
set tmp_dir=%TEMP%\temp-android-tool
xcopy %swt_path% %tmp_dir%\%swt_path% /I /E /C /G /R /Y /Q > nul
copy /B /D /Y lib\androidprefs.jar %tmp_dir%\lib\ > nul
copy /B /D /Y lib\org.eclipse.* %tmp_dir%\lib\ > nul
copy /B /D /Y lib\sdk* %tmp_dir%\lib\ > nul
copy /B /D /Y lib\common.jar %tmp_dir%\lib\ > nul
copy /B /D /Y lib\commons-compress* %tmp_dir%\lib\ > nul
copy /B /D /Y lib\swtmenubar.jar %tmp_dir%\lib\ > nul
copy /B /D /Y lib\commons-logging* %tmp_dir%\lib\ > nul
copy /B /D /Y lib\commons-codec* %tmp_dir%\lib\ > nul
copy /B /D /Y lib\httpclient* %tmp_dir%\lib\ > nul
copy /B /D /Y lib\httpcore* %tmp_dir%\lib\ > nul
copy /B /D /Y lib\httpmime* %tmp_dir%\lib\ > nul
rem jar_path and swt_path are relative to PWD so we don't need to adjust them, just change dirs.
set tools_dir=%cd%
cd /d %tmp_dir%
:EndTempCopy
rem The global ANDROID_SWT always override the SWT.Jar path
if defined ANDROID_SWT set swt_path=%ANDROID_SWT%
if exist %swt_path% goto SetPath
echo ERROR: SWT folder '%swt_path%' does not exist.
echo Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
goto :EOF
:SetPath
rem Finally exec the java program and end here.
REM set REMOTE_DEBUG=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
call %java_exe% %REMOTE_DEBUG% -Dcom.android.sdkmanager.toolsdir="%tools_dir%" -Dcom.android.sdkmanager.workdir=%work_dir% -classpath "%jar_path%;%swt_path%\swt.jar" com.android.sdkmanager.Main %*
rem EOF
Update (again)
更新(再次)
I installed the Android SDK on WinXP running in virtualbox and it works perfectly. I would still rather be able to use it on Win7 though.
我在运行在 virtualbox 中的 WinXP 上安装了 Android SDK,它运行良好。不过,我仍然希望能够在 Win7 上使用它。
采纳答案by merlin
I installed a new x64 version of the JDK and that fixed my issue
我安装了新的 x64 版本的 JDK 并解决了我的问题
回答by user2345534
This is how I got it to work on Windows 8
这就是我让它在 Windows 8 上工作的方式
Add the JAVA_HOME environment variable and set it to your java install location (i.e.
C:\Program Files (x86)\Java\jdk1.6.0_39\bin
)Next edit C:\Users{YOUR USERNAME}\AppData\Local\Android\android-sdk\tools\android.bat Find the
set java_exe= call lib\find_java.bat
line and change it toset java_exe=java.exe
Save the file and it should run
添加 JAVA_HOME 环境变量并将其设置为您的 java 安装位置(即
C:\Program Files (x86)\Java\jdk1.6.0_39\bin
)接下来编辑 C:\Users{YOUR USERNAME}\AppData\Local\Android\android-sdk\tools\android.bat 找到该
set java_exe= call lib\find_java.bat
行并更改为set java_exe=java.exe
保存文件,它应该运行
Noteif you get an error about the swt location simply hardcode the path. Set it to lib\x86 or lib\x86_64
请注意,如果您收到有关 swt 位置的错误,只需对路径进行硬编码。将其设置为 lib\x86 或 lib\x86_64
Hope this helps
希望这可以帮助
回答by Julian Higginson
I had this problem with a fresh install of 64 bit win 7 pro, using and a fresh install of the 64 bit JDK.
我在全新安装 64 位 win 7 pro、使用和全新安装 64 位 JDK 时遇到了这个问题。
Kenton Price's solution in this post fixed me up, and now it all works perfectly.
Kenton Price 在这篇文章中的解决方案修复了我,现在一切都完美无缺。
Android SDK installation doesn't find JDK
for some reason the (originally linux developed) ADK on my system needed JAVA_HOME defined with linux style forward slashes instead of windows style backslashes.
出于某种原因,我系统上的(最初是 linux 开发的)ADK 需要用 linux 风格的正斜杠而不是 windows 风格的反斜杠定义的 JAVA_HOME。
回答by Todd
I found the same problem that Rajesh found from his comment above. The command in parentheses on this line was not executing
我发现了 Rajesh 从上面的评论中发现的同样问题。此行括号中的命令未执行
for /f "delims=" %%a in ('"%java_exe%" -jar lib\archquery.jar') do set swt_path=lib\%%a
Edit: some people may have this line: for /f "delims=" %%a in ('"%~dps0find_java%arch_ext%.exe" -s') do set java_exe=%%a
编辑:有些人可能有这一行: for /f "delims=" %%a in ('"%~dps0find_java%arch_ext%.exe" -s') do set java_exe=%%a
This line is from find_java.bat
in the tools\lib\
directory of the sdk.
这一行来自sdkfind_java.bat
的tools\lib\
目录。
I have a Win 7 x64 system and I'm not about to reload the entire OS so I hardcoded what MZB suggested from his post above:
我有一个 Win 7 x64 系统,我不打算重新加载整个操作系统,所以我硬编码了 MZB 从他上面的帖子中建议的内容:
After this line:
在这一行之后:
for /f "delims=" %%a in ('"%java_exe%" -jar lib\archquery.jar') do set swt_path=lib\%%a
edit: or this line:
编辑:或这一行:
for /f "delims=" %%a in ('"%~dps0find_java%arch_ext%.exe" -s') do set java_exe=%%a
对于 /f "delims=" %%a in ('"%~dps0find_java%arch_ext%.exe" -s') 设置 java_exe=%%a
I added this line:
我添加了这一行:
set java_exe=%JAVA_HOME%\bin\java.exe
This assumes you have the JAVA_HOME environment variable set to the Java JDK folder (without \bin
)
这假设您将 JAVA_HOME 环境变量设置为 Java JDK 文件夹(没有\bin
)
If your JAVA_HOME variable includes the \bin
then set it like this:
如果您的 JAVA_HOME 变量包含 ,\bin
则将其设置为:
set java_exe=%JAVA_HOME%\java.exe
If you don't have the JAVA_HOME environment set, then you need to hard code it with the actual path you have on your machine as MZB did in his post.
如果您没有设置 JAVA_HOME 环境,那么您需要使用机器上的实际路径对其进行硬编码,就像 MZB 在他的帖子中所做的那样。
I also did it for the javaw logic too:
我也为 javaw 逻辑做了它:
set javaw_exe=%JAVA_HOME%\bin\javaw.exe
I can finally access the SDK Manager.
我终于可以访问 SDK 管理器了。
UPDATE 06/01/2015:
更新 06/01/2015:
To Ken Y-N who updated this post after I submitted it:
致在我提交后更新这篇文章的 Ken YN:
When I created this post, I had referenced this line:
当我创建这篇文章时,我引用了这一行:
for /f "delims=" %%a in ('"%~dps0find_java%arch_ext%.exe" -s') do set java_exe=%%a
对于 /f "delims=" %%a in ('"%~dps0find_java%arch_ext%.exe" -s') 设置 java_exe=%%a
This in in my current find_java.bat from folder ...\sdk\tools\lib which I just updated yesterday from the current version of Android Studio Windows x64 version (android-studio-bundle-141.1903250-windows.exe). the variable %arch_ext% will either have 32 or 64 in it depending on what system they have.
这在我当前从文件夹 ...\sdk\tools\lib 中找到的 find_java.bat 中,我昨天刚刚从当前版本的 Android Studio Windows x64 版本 (android-studio-bundle-141.1903250-windows.exe) 更新了它。变量 %arch_ext% 将包含 32 或 64,具体取决于它们拥有的系统。
But I don't know how the above line got converted to:
但我不知道上面的行是如何转换为:
for /f "delims=" %%a in ('"%java_exe%" -jar lib\archquery.jar') do set swt_path=lib\%%a
for /f "delims=" %%a in ('"%java_exe%" -jar lib\archquery.jar') 设置 swt_path=lib\%%a
after Ken Y-N did the edit.
在 Ken YN 进行编辑之后。
But perhaps some people have your version in their find_java.bat file but I would believe some people have the other like I do. I'm just pointing this out for those that are having a problem not being able to open their SDK Manager.
但也许有些人在他们的 find_java.bat 文件中有你的版本,但我相信有些人像我一样有另一个。我只是为那些遇到无法打开 SDK 管理器问题的人指出这一点。
Plus I should mention I had this problem with both JDK1.7 and JDK1.8. I had originally installed JDK1.8 but when reading the requirements for Android Studio yesterday, it said JDK1.7 was required, so I installed JDK1.7 last night thinking that would solve my problem, but the problem with find_java.bat was the same with either version of JDK.
另外我应该提到我在 JDK1.7 和 JDK1.8 上都有这个问题。本来是装JDK1.8的,昨天看Android Studio的要求,说需要JDK1.7,所以我昨晚装了JDK1.7,以为可以解决我的问题,但是find_java.bat的问题还是一样使用任一版本的 JDK。
I should point out too, when I installed Android Studio with both versions of the JDK, I was originally able to access the SDK Manager before opening up Android Studio for the first time. But when I opened up Android Studio, it started updating the SDK Manager first and maybe that's when the problem occurs because after starting up an IDEA project, I could not open up the SDK Manager after that.
我还要指出,当我安装带有两个版本的 JDK 的 Android Studio 时,我最初能够在第一次打开 Android Studio 之前访问 SDK Manager。但是当我打开Android Studio时,它首先开始更新SDK Manager,也许这就是问题发生的时候,因为启动IDEA项目后,我无法打开SDK Manager。
So maybe find_java.bat has this line BEFORE opening up Android Studio for the first time:
所以也许 find_java.bat 在第一次打开 Android Studio 之前有这行:
for /f "delims=" %%a in ('"%java_exe%" -jar lib\archquery.jar') do set swt_path=lib\%%a
for /f "delims=" %%a in ('"%java_exe%" -jar lib\archquery.jar') 设置 swt_path=lib\%%a
And when Adroid Studio updates the SDK, it the has this line?
当 Adroid Studio 更新 SDK 时,它有这条线吗?
for /f "delims=" %%a in ('"%~dps0find_java%arch_ext%.exe" -s') do set java_exe=%%a
对于 /f "delims=" %%a in ('"%~dps0find_java%arch_ext%.exe" -s') 设置 java_exe=%%a
I don't have time to test that out - I already lost so much time trying to figure out how to access the SDK. Maybe someone else can confirm this if they're having the same problem.
我没有时间进行测试 - 我已经浪费了太多时间试图弄清楚如何访问 SDK。如果他们遇到同样的问题,也许其他人可以确认这一点。
回答by user2045798
I also had same problem not able to open Android SDK manager, but by Deleting the .android folder from the user (C:/Users/[User Name]) directory it works...
我也遇到了同样的问题,无法打开 Android SDK 管理器,但是通过从用户 (C:/Users/[User Name]) 目录中删除 .android 文件夹,它可以工作...
Thanks
谢谢
回答by Tomym617
I just ran into a similar problem as lopsided98 had and tried all the solutions on here also and no results. then I remembered that I had to add an environment variable to locate java before i could get android studio to start in the first place so I just tried adding a new system variable for Android_home
and directed it to my android folder C:\Program Files (x86)\Android
. Just like I had done when setting up java and then it started up with no problems. SDK manager is also up and working now. I hope this helps, if you're still having problems
我刚刚遇到了与 lopside98 类似的问题,并在这里尝试了所有解决方案,但没有结果。然后我记得我必须添加一个环境变量来定位 java,然后才能让 android studio 首先启动,所以我只是尝试添加一个新的系统变量Android_home
并将其定向到我的 android 文件夹C:\Program Files (x86)\Android
。就像我在设置 java 时所做的那样,然后它就没有问题地启动了。SDK 管理器也已启动并正在运行。我希望这会有所帮助,如果您仍然遇到问题
This was what i had found when setting up the java part and just thought I might give it a try for android too.
这是我在设置 java 部分时发现的,只是想我也可以尝试一下 android。
On some Windows systems, the launcher script does not find where Java is installed. If you encounter this problem, you need to set an environment variable indicating the correct location.
在某些 Windows 系统上,启动程序脚本找不到 Java 的安装位置。如果遇到此问题,则需要设置一个环境变量来指示正确的位置。
Select Start menu > Computer > System Properties > Advanced System Properties.
选择开始菜单 > 计算机 > 系统属性 > 高级系统属性。
Then open Advanced tab > Environment Variables
and add a new system variable JAVA_HOME
that points to your JDK folder, for example
然后打开Advanced tab > Environment Variables
并添加一个JAVA_HOME
指向 JDK 文件夹的新系统变量,例如
C:\Program Files\Java\jdk1.7.0_21.
C:\Program Files\Java\jdk1.7.0_21。
回答by Jaydeep
If the problem is on Windows machine, then just run the AVD Manager or the SDK Manager as Administrator
如果问题出在 Windows 机器上,那么只需以管理员身份运行 AVD Manager 或 SDK Manager
回答by MZB
There may be an issue with \tools\lib\find_java.bat not successfully determining the location of the java.exe and javaw.exe executables.
\tools\lib\find_java.bat 可能存在问题,无法成功确定 java.exe 和 javaw.exe 可执行文件的位置。
The workaround here: http://www.gmansoft.com/android-sdk-manager-find-java-problem/worked for me. Note that if you "fix" the problem in android.bat other batch files will still be broken.
这里的解决方法:http://www.gmansoft.com/android-sdk-manager-find-java-problem/ 对我有用。请注意,如果您“修复” android.bat 中的问题,其他批处理文件仍将被破坏。
In case the above link breaks, the workaround is to hardwire the results of find_java.bat to return the actual location of the java executables. e.g. edit it to be something like:
如果上述链接中断,解决方法是将 find_java.bat 的结果硬连线以返回 java 可执行文件的实际位置。例如编辑它是这样的:
rem Check we have a valid Java.exe in the path. The return code will
rem be 0 if the command worked or 1 if the exec failed (program not found).
rem for /f "delims=" %%a in ('"%~dps0\find_java%arch_ext%.exe" -s') do set java_exe=%%a
set java_exe=c:\program files\Java\jdk1.8.0_25\bin\java.exe
if not defined java_exe goto :CheckFailed
:SearchJavaW
rem Check if we can find a javaw.exe at the same location than java.exe.
rem If that doesn't work, just fall back on the java.exe we just found.
rem for /f "delims=" %%a in ('"%~dps0\find_java%arch_ext%.exe" -s -w') do set javaw_exe=%%a
set javaw_exe=c:\program files\Java\jdk1.8.0_25\bin\javaw.exe
if not exist "%javaw_exe%" set javaw_exe=%java_exe%
goto :EOF
回答by deko
I faced the same issue when upgraded my working environment. The issue was in <AndroidSDK>\tools\lib\find_java.bat
(thanx anyone who pointed to this file). It searched for 64-bit version of Java, while I had 32-bit version installed. Simple and dirty set arch_ext=32
in find_java.bat
solved the issue for me.
升级我的工作环境时,我遇到了同样的问题。问题出在<AndroidSDK>\tools\lib\find_java.bat
(感谢任何指向此文件的人)。它搜索了 64 位版本的 Java,而我安装了 32 位版本。简单的和肮脏set arch_ext=32
的find_java.bat
解决了这个问题对我来说。
回答by Prakash
Dont delete the .android folder. Juz delete the avd folder within the .android folder. It shld do a lot of good to your work.
不要删除 .android 文件夹。Juz 删除 .android 文件夹中的 avd 文件夹。它对你的工作大有裨益。
Advance cheers. Prakash.
提前欢呼。普拉卡什。