How to fix "Error - Failed to execute tools\android.bat, error 2 " in Android?
Please check your COMSPEC environment variable (intuitive, I know).
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).
To check this, in a command window, type
echo %COMSPEC%
The resulting value should probably be 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.
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.
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.
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.
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.
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.
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.
My android.bat
file was missing when updating the particular SDK package and my computer suddenly shut down. Thus, my tools folder became empty.
You can recover your android.bat
file from temp folder
Manually unzip tools_r23.05-windows or any tool_rXX.zip file (red color)
Get a folder called tools (orange color)
Copy all the file in this folder to the original
tools
folder (outside temp folder, e.g. D:\android-sdk\tools)
In my case, the problem was solved this way. Hope this helps.