Is not recognized as an internal or external command, operable program or batch file Android Studio

When I run the following command in PowerShell on Windows 10, I get an error:

cordova build android --verbose => ... Running command: C:\MyPath\platforms\android\gradlew cdvBuildDebug -b C:\MyPath\platforms\android\build.gradle 'sh' is not recognized as an internal or external command, operable program or batch file. Command finished with error code 1: C:\MyPath\platforms\android\gradlew cdvBuildDebug,-b,C:\MyPath\platforms\android\build.gradle C:\MyPath\platforms\android\gradlew: Command failed with exit code 1 Error output: 'sh' is not recognized as an internal or external command, operable program or batch file. Error: C:\MyPath\platforms\android\gradlew: Command failed with exit code 1 Error output: 'sh' is not recognized as an internal or external command, operable program or batch file. at ChildProcess.whenDone (C:\MyPath\node_modules\cordova-common\src\superspawn.js:135:23) at ChildProcess.emit (events.js:315:20) at ChildProcess.cp.emit (C:\MyPath\node_modules\cross-spawn\lib\enoent.js:34:29) at maybeClose (internal/child_process.js:1021:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)

What is expected to happen?

I am able to run this command on Ubuntu (non-WSL) and it successfully finds the correct version of gradlew. However, in Windows, I think it should find gradlew.bat.

What does actually happen?

It runs gradlew on Windows, rather than gradlew.bat

Information

check_reqs.js locates Android Studio and then gradle in this location:

C:\Program Files\Android\Android Studio\gradle\gradle-4.6\bin\gradle

However, ProjectBuilder.js shows this:

build (opts) { var wrapper = path.join(this.root, 'gradlew'); ...

It looks to me like there is no attempt to append .bat to the filename if it’s on Windows. Maybe execa is supposed to append it, but it doesn’t seem to. If I hack this to ‘gradlew.bat’, it builds successfully.

Command or Code

cordova build android --verbose

Environment, Platform, Device

Windows 10

Version information

Cordova 9.0.0 It seems to find Android Studio 3.2.1, although I’m not actually using it.

Checklist

Your comment on this question:

Your comment on this answer:

In this post, we are going to show how to fix 'flutter' is not recognized as an internal or external command error in Windows OS. In PowerShell, the error may look like below: 

flutter : The term 'flutter' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

This error happens when Flutter is not installed correctly in your OS. To solve this issue Follow the following methods.

1. First get the location where Flutter SDK. 

First, you need to locate the Flutter SDK folder in your files. If you do not have Flutter SDK on your local computer, download Flutter SKD from its official website. Here, our SDK is located at C:\Users\username\Documents\flutter_sdk\flutter . You have to edit the PATH Environment variable and add new path with "bin/". For example: C:\Users\username\Documents\flutter_sdk\flutter\bin

Is not recognized as an internal or external command, operable program or batch file Android Studio

2. Go to My Computer Properties > Advance System Setting > Environment Variables

Go to this path and edit the PATH variable and add a new path of your Flutter SDK with "bin\" folder. For example: C:\Users\username\Documents\flutter_sdk\flutter\bin

Is not recognized as an internal or external command, operable program or batch file Android Studio

Save the changes and restart your terminal and hit the command below:

flutter doctor

The output will look like below:

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.5.3, on Microsoft Windows [Version 10.0.22000.318], locale en-US)
...

more outputs

In this way, you can solve 'flutter' is not recognized as an internal or external command error in Windows OS.

Keytool is a free command line tool that is added to your system when you install Java.

If you want to build an Android APK binary that can be distributed on the Play Store, you need to use keytool to generate the SHA-1 fingerprint for your signing certificate.

This is a required step when configuring the Firebase SDK for your Android (or Flutter) app.

This page on the official documentation explains how to use keytool, but not how to install it.

So if you got stuck with this before, this article explains all the required steps.

sponsor

Code with Andrea is free for everyone. Help me keep it that way by checking out this sponsor:

Is not recognized as an internal or external command, operable program or batch file Android Studio

10x your Flutter productivity. Use FlutterFlow's visual builder to generate clean Flutter code and take your Flutter productivity to the next level. FlutterFlow comes with Flutter + Firebase integration, custom code extensibility, web app + multi-language support, and one-click deploy enabling you to ship apps faster than ever.

Ready? let's go!

Getting the SHA-1 certificate fingerprint with keytool

This is how to use keytool to get the debug SHA-1 certificate fingerprint on Windows:

keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore

And this is the equivalent on macOS/Linux:

keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore

However, the commands above will only work if you have keytool already installed on your system, and it is included in your system PATH.

'keytool' is not recognized as an internal or external command, operable program or batch file.

If this is not the case, you'll be greeted with this message (on Windows):

'keytool' is not recognized as an internal or external command,
operable program or batch file.'keytool' is not recognized as an internal or external command, operable program or batch file.

Let's fix this.

Install keytool on your system

Keytool is included as part of the Java runtime. So by installing Java, you'll also have keytool in your system.

To install Java, visit the JAVA SE Downloads page.

Then, select the JDK Download link.

This takes you to a page called "Java SE Development Kit 15 Downloads".

Scroll to the bottom, and you'll find download links for Linux, macOS and Windows.

Java SE Download linksJava SE Download links

Download the correct installer (jdk-15.0.1_windows-x64_bin.exe on Windows, jdk-15.0.1_osx-x64_bin.dmg on macOS). Then follow the installation steps for your system and make a note of where this is installed (e.g. C:\Program Files\Java\jdk-15.0.1\ on Windows).

Congratulations, the Java SDK is now installed on your system.

Add the keytool folder to your system PATH (on Windows)

In order to run keytool from the command line, you need to add it to your system PATH.

This step is required on Windows only, as keytool will is automatically installed on /usr/bin on macOS/Linux.

On the search box, type path, then open Edit the system environment variables (Control panel):

This opens the Advanced tab of the System Properties dialog:

From here, select Environment Variables..., which opens this dialog:

You'll see that both the User variables and System variables have a Path variable. It doesn't really matter which one you choose. For this example, we'll edit the User variables one.

The next dialog shows the environment variables for the current user. Select New, then add a new line pointing to your jdk installation folder, with a trailing \bin at the end (e.g. C:\Program Files\Java\jdk-15.0.1\bin):

Then press OK and close all the dialogs, then open a new command prompt.

Try running keytool. This time you should get this output:

C:\Users\salta>keytool Key and Certificate Management Tool Commands: -certreq Generates a certificate request -changealias Changes an entry's alias -delete Deletes an entry -exportcert Exports certificate -genkeypair Generates a key pair -genseckey Generates a secret key -gencert Generates certificate from a certificate request -importcert Imports a certificate or a certificate chain -importpass Imports a password -importkeystore Imports one or all entries from another keystore -keypasswd Changes the key password of an entry -list Lists entries in a keystore -printcert Prints the content of a certificate -printcertreq Prints the content of a certificate request -printcrl Prints the content of a CRL file -storepasswd Changes the store password of a keystore -showinfo Displays security-related information Use "keytool -?, -h, or --help" for this help message Use "keytool -command_name --help" for usage of command_name. Use the -conf <url> option to specify a pre-configured options file.

This confirms that keytool is installed and configured in your PATH.

Using keytool to generate te SHA-1

You're now ready to generate your SHA-1:

keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore

This will work, if you already have a keystore at the given location (%USERPROFILE%\.android\debug.keystore). If not you'll get this error:

keytool error: java.lang.Exception: Keystore file does not exist: C:\Users\salta\.android\debug.keystore java.lang.Exception: Keystore file does not exist: C:\Users\salta\.android\debug.keystore at java.base/sun.security.tools.keytool.Main.doCommands(Main.java:916) at java.base/sun.security.tools.keytool.Main.run(Main.java:422) at java.base/sun.security.tools.keytool.Main.main(Main.java:415)

If you don't have a keystore, you'll need to generate one with Android Studio. This document about app signing on Android includes the information you need.

Conclusion

Phew! Getting keytool running on Windows requires a few steps, but we got there in the end.

If I have missed something, let me know on Twitter.

Happy coding!