如何修复 Android 中的“错误 - 无法执行 tools\android.bat,错误 2”?

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

How to fix "Error - Failed to execute tools\android.bat, error 2 " in Android?

android

提问by Prem

When i click on AVD Manager, i am getting an error as in the screenshot below.

当我单击 AVD 管理器时,出现如下屏幕截图所示的错误。

Referred to the following links. But none of the solution works for me.

参考以下链接。但是没有一个解决方案适合我。

Failed to execute tools\android.bat: solution

执行tools\android.bat失败:解决方法

Android SDK Windows Failed to execute Android.bat

Android SDK Windows 执行 Android.bat 失败

https://android.stackexchange.com/questions/33538/android-sdk-cant-find-android-bat

https://android.stackexchange.com/questions/33538/android-sdk-cant-find-android-bat

In Tools -> Lib Folder i have my AVD Manager.

在工具 -> Lib 文件夹中,我有我的 AVD 管理器。

In Tools -> i have android.bat

在工具 -> 我有 android.bat

I tried the following options and it did not work.

我尝试了以下选项,但没有奏效。

  1. Copied Android SDK Manager in Lib folder and clicked on AVD Manager. Got the same error.
  2. Copied AVD Manager to Tools folder and clicked AVD Manager. Got the same error.
  1. 在 Lib 文件夹中复制 Android SDK Manager 并单击 AVD Manager。得到了同样的错误。
  2. 将 AVD Manager 复制到 Tools 文件夹并单击 AVD Manager。得到了同样的错误。

Please find below the error screenshot.

请在下面的错误屏幕截图中找到。

enter image description here

在此处输入图片说明

Kindly let me know if any thoughts.

如果有任何想法,请告诉我。

回答by yean

My android.batfile was missing when updating the particular SDK package and my computer suddenly shut down. Thus, my tools folder became empty.

android.bat更新特定 SDK 包时我的文件丢失,我的计算机突然关闭。因此,我的工具文件夹变空了。

enter image description here

在此处输入图片说明

You can recover your android.batfile from tempfolder

您可以android.bat临时文件夹中恢复您的文件

enter image description here

在此处输入图片说明

  1. Manually unzip tools_r23.05-windowsor any tool_rXX.zipfile (red color)

  2. Get a folder called tools(orange color)

  3. Copy allthe file in this folder to the original toolsfolder (outside temp folder, e.g. D:\android-sdk\tools)

  1. 手动解压缩tools_r23.05-windows或任何tool_rXX.zip文件(红色)

  2. 获取一个名为tools(橙色)的文件夹

  3. 将这个文件夹中的所有文件复制到原tools文件夹(临时文件夹外,例如D:\android-sdk\tools)

In my case, the problem was solved this way. Hope this helps.

就我而言,问题是这样解决的。希望这可以帮助。

回答by d9n

Please check your COMSPEC environment variable (intuitive, I know).

请检查您的 COMSPEC 环境变量(直觉,我知道)。

There are apparently some programs that modify this, which in turn break these Android tools (and presumably other programs that rely on .bat files as well).

显然有一些程序会修改它,从而破坏这些 Android 工具(可能还有其他依赖 .bat 文件的程序)。

To check this, in a command window, type

要检查这一点,请在命令窗口中键入

echo %COMSPEC%

回声%COMSPEC%

The resulting value should probably be C:\Windows\System32\cmd.exe

结果值应该是 C:\Windows\System32\cmd.exe

If you have multiple exes jammed in there, or if the variable ends with a semicolon, you've got a broken COMSPEC variable. If so, please edit your system's environment variables and fix it, setting it to the cmd.exe path above.

如果您有多个 exe 卡在那里,或者如果变量以分号结尾,则您的 COMSPEC 变量已损坏。如果是这样,请编辑系统的环境变量并修复它,将其设置为上面的 cmd.exe 路径。

回答by Sulung Nugroho

I got the same problem and I found where it's come from. I know it's a 2 year question, but the problem still remain the same for some people.

我遇到了同样的问题,我找到了它的来源。我知道这是一个 2 年的问题,但对于某些人来说问题仍然存在。

Cannot run program "C:\Users\Hp\AppData\Local\Android\Sdk\tools\android.bat

It will happen when we re-install android studio for some reasons. I even re-installed it 4 times. Problem came at the first time I re-installed. I tried to re-install again and again but the problem remain the same.

由于某些原因,当我们重新安装android studio时会发生这种情况。我什至重新安装了4次。我第一次重新安装时出现问题。我一次又一次地尝试重新安装,但问题仍然存在。

Finally I open C:\Users\Hp\AppData that actually hidden. And in the next folder \local\Android\Sdk, now I found some folder Sdk, Sdk1, Sdk2, and Sdk3.

最后我打开实际上隐藏的 C:\Users\Hp\AppData。在下一个文件夹\local\Android\Sdk 中,现在我找到了一些文件夹 Sdk、Sdk1、Sdk2 和 Sdk3。

Now I remember, as I re-installed it 4 times, that's why I have four folders. I remove ( not actually remove, but rename it with additional XX at the end of folder name) Sdk folder and change Sdk3 to Sdk. Now everything is working fine.

现在我记得,因为我重新安装了 4 次,这就是为什么我有四个文件夹。我删除(实际上不是删除,而是在文件夹名称末尾使用附加 XX 重命名)Sdk 文件夹并将 Sdk3 更改为 Sdk。现在一切正常。

Why? because my last re-install create Sdk3 folder that contain android.bat required for the main program where no more exist in the first Sdk folder.

为什么?因为我上次重新安装创建了包含主程序所需的 android.bat 的 Sdk3 文件夹,其中第一个 Sdk 文件夹中不再存在。

Before I got this as well :

在我得到这个之前:

Error:Execution failed for task ':app:compileDebugAidl'. > java.lang.IllegalStateException: aidl is missing

And now it's missing and the problem is solved.

现在它不见了,问题解决了。

If you happen got the same problem with me. hope it could help you.

如果你碰巧和我有同样的问题。希望它可以帮助你。

回答by user3927896

In my case.Android root folder was readonly. -->Remove readonly tick

在我的情况下,Android 根文件夹是只读的。--> 删除只读勾选

回答by ddagsan

I had this problem and downloaded tools_r25.2.3-windows.zip file. I think this problem caused on updating tools. I deleted tools to update but this error occured when I installed. Be careful updating.

我遇到了这个问题并下载了 tools_r25.2.3-windows.zip 文件。我认为这个问题是由更新工具引起的。我删除了要更新的工具,但安装时出现此错误。小心更新。

回答by user8660530

It needs to copy those " SDK Manager.exe " and "AVD Manager.exe" to the SDK root folder, I needed to copy them to C:\android-sdk\ form Lib Folder, this is because, SDK Manager.exe and AVD Manager.exe are looking for tools

它需要将那些“SDK Manager.exe”和“AVD Manager.exe”复制到SDK根文件夹中,我需要将它们复制到C:\android-sdk\形式的Lib文件夹中,这是因为,SDK Manager.exe和AVD Manager.exe 正在寻找工具

回答by Qwertie

My situation: Right after installing Android support into Visual Studio, the "Open Android Emulator Manager (AVD)" button was broken and running C:\Program Files (x86)\Android\android-sdk\tools\lib\AVD Manager.exeproduces the error shown by the OP. The screenshot in yean's answer shows an android-sdk folder that contains AVD Manager.exe, but my android-sdk folder did not contain any files (only folders).

我的情况:在 Visual Studio 中安装 Android 支持后,“Open Android Emulator Manager (AVD)”按钮被破坏并运行C:\Program Files (x86)\Android\android-sdk\tools\lib\AVD Manager.exe产生 OP 显示的错误。yean 答案中的屏幕截图显示了一个包含 AVD Manager.exe 的 android-sdk 文件夹,但我的 android-sdk 文件夹不包含任何文件(仅文件夹)。

Crazy as it sounds, simply copying AVD Manager.exefrom android-sdk\tools\libto android-sdkfixes both problems. (I couldn't create an API-18 arm emulator but API-19 worked.)

听起来很疯狂,只需将AVD Manager.exeandroid-sdk\tools\lib复制到android-sdk 即可解决这两个问题。(我无法创建 API-18 arm 模拟器,但 API-19 可以工作。)

回答by cd491415

This wasn't working for me as I did not have this bat file nor the tools directory at all. And my temp directory did not have any zipped tools directory, so could not just replace.

这对我不起作用,因为我根本没有这个 bat 文件,也没有工具目录。而且我的临时目录没有任何压缩的工具目录,所以不能只是替换。

MS suggested doing repair install

MS 建议进行修复安装

  1. Open the Windows Programs and Features Control Panel.
  2. Right click the relevant Microsoft Visual Studio entry, and select Change
  3. Click the Repair button in the Visual Studio dialog that opens.
  1. 打开 Windows 程序和功能控制面板。
  2. 右键单击相关的 Microsoft Visual Studio 条目,然后选择更改
  3. 单击打开的 Visual Studio 对话框中的修复按钮。

That resolved my issue

这解决了我的问题

回答by Frosty Z

Happened several times on my environment. @Mahmood and @Qwertie solutions did help, until today.

在我的环境中发生了几次。@Mahmood 和 @Qwertie 解决方案确实有帮助,直到今天。

Banged my head the whole afternoon searching & trying many solutions... finally this oneunlocked the situation:

整个下午都在敲我的头,搜索并尝试了许多解决方案......最后这个解决了这个问题:

Remove hidden directory C:\Users\{yourUserName}\.android

删除隐藏目录 C:\Users\{yourUserName}\.android

回答by Doug

I have a x86 system (not x86_64).

我有一个 x86 系统(不是 x86_64)。

in tools\lib\find_jave.bat I replaced:

在 tools\lib\find_jave.bat 我替换了:

  find /i "x86" > NUL && set arch_ext=32 || set arch_ext=64

With:

和:

  rem find /i "x86" > NUL && set arch_ext=32 || set arch_ext=64
  set arch_ext=32

Then when android.bat runs, it prints:

然后当 android.bat 运行时,它会打印:

  The system cannot find the file specified.

Yet it DOES run the SDK manager.

但它确实运行 SDK 管理器。

I suspect the 'find' line is broken. If you have a 64 bit system, try setting arch_ext to 64 and test that.

我怀疑“查找”线坏了。如果您有 64 位系统,请尝试将 arch_ext 设置为 64 并进行测试。