apache / apache/cordova-android
gradlew: 'sh' is not recognized as an internal or external command,
- Dominant language
- JavaScript
- Stars
- 3.8k
- Forks
- 1.6k
- Avg merge
- 16h 18m
- Merged PRs (30d)
- 11
Description
# 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](https://github.com/apache/cordova-android/blob/master/bin/templates/cordova/lib/builders/ProjectBuilder.js#L347):
```javascript
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](https://github.com/sindresorhus/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
- [X] I searched for existing GitHub issues
- [X] I updated all Cordova tooling to most recent version
- [X] I included all the necessary information above
Contributor guide
Research direction
Start in bin/templates/cordova/lib/builders/ProjectBuilder.js around the build method shown in the issue, then reproduce with `cordova build android --verbose` on Windows 10. Check how the Android Gradle wrapper is selected and verify that the Windows build invokes gradlew.bat and completes successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- build-system, mobile-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100