question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gradlew: 'sh' is not recognized as an internal or external command,

See original GitHub issue

Bug Report

Problem

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

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:18 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
EnginKARATAScommented, Mar 26, 2022

I have confirmed “sh” error caused by when emulator not start

4reactions
1aerostormcommented, Apr 30, 2022

Faced this issue on Windows when using device, but it is disconnected, so cordova-android tried to running emulator.

It uses emulator and run that command when adb devices returns empty list, so you can run adb devices and ensure that here is your device (or pre-runned emulator?)

Problem is in apkanalyzer which is a file in

C:\Users\<username>\AppData\Local\Android\Sdk\tools\bin

and it is shell script, not cmd…

I think it is a bug in Android SDK. More info: https://stackoverflow.com/questions/47081004/apkanalyzer-is-not-recognized-as-an-internal-or-external-command But if they aren’t fixing it, it should be work-arounded in cordova-android…

Read more comments on GitHub >

github_iconTop Results From Across the Web

'gradlew' is not recognized as an internal or external command
Here is the terminal output: 'gradlew' is not recognized as an internal or external command, operable program or batch file.
Read more >
gradle is not recognized as an internal or external command
gradle is not recognized as an internal or external command. Watch later. Share. Copy link. Info. Shopping. Tap to unmute.
Read more >
gradlew command not found - YouTube
gradlew command not found. Watch later. Share. Copy link. Info. Shopping. Tap to unmute. If playback doesn't begin shortly, try restarting ...
Read more >
'gradle' is not recognized internal or external command
select the $path variable. · Copied the content of value in notepad, · Manually added the gradle-XXX/ bin directory. copy& paste it value...
Read more >
Run Your Gradle Build Anywhere with the Gradle Wrapper
You might have to update the Gradle version in the future. We can achieve this by running the command ./gradlew wrapper --gradle-version < ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found