react-native: [Windows] Gradle release build fails when spaces are in directory path

Description

I’m on Windows. When building my app for release in Android Studio, I receive the following error after Metro successfully generates the assets:

'C:\Users\Micah' is not is not recognized as an internal or external command, operable program or batch file.

The path of the repository is C:\Users\Micah Lindley\Documents\Code\repo. This appears to be an issue with switching over to Hermes as Android Studio says it’s tied to this line:

https://github.com/facebook/react-native/blob/36c971695c1fa356b71298a2f1f583ed66fdd182/react.gradle#L286

Help on this is much appreciated, since this prevents my app from being built!

Version

0.70.2

Output of npx react-native info

System: OS: Windows 10 10.0.22621 CPU: (16) x64 AMD Ryzen 9 5900HX with Radeon Graphics
Memory: 14.97 GB / 31.41 GB Binaries: Node: 16.15.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD Watchman: Not Found SDKs: Android SDK: Not Found Windows SDK: Not Found IDEs: Android Studio: AI-212.5712.43.2112.8512546 Visual Studio: Not Found Languages: Java: Not Found npmPackages: @react-native-community/cli: Not Found react: Not Found react-native: Not Found react-native-windows: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

  1. Create a RN app in a folder with a space in the name
  2. Open Android Studio
  3. Generate a release
  4. See the error

Snack, code example, screenshot, or link to a repository

https://github.com/micahlt/wasteofmobile/tree/reactnative

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 35 (14 by maintainers)

Commits related to this issue

Most upvoted comments

@cortinico, @kelset, @shivenmian is working on a fix … This issue brings back the topic of the recommended shell for RN development on Windows, as the escaping strategy differs between powershell and cmd (and others…) … Ideally the fix should work across all the shells.

This has been fixed by @shivenmian here:

We’ll ship it in the next version or point release for 0.71 👍

I’ve spent some time on this and I’m not able to find a simple solution. We would need to properly escape the path for Windows only. This seems to be non trivial with Gradle. I’m happy to review a PR if someone is willing to try to debug/solve this (I can provide codepointers if needed).

As this is happening only on Windows and only on Hermes and only inside folders that have a space in the path, I think this is not a release blocker (for .71).

I have the suspect this was broken even before. I would appreciate if someone from Microsoft can take a look at this @mganandraj @kelset

I’m working on a fix. You can assign this to me.

Apparently this isn’t high priority, even though it fully breaks RN on any modern Windows machine (since Windows Setup automatically creates a home folder with a space in it. The only solution is to create a new folder somewhere like C:\Code and build the project from there. You just have to set up the permissions correctly.

I’ll get back to this on Monday when I’ll have access to my Windows machine to fix it.

I think Nicola just want to verify that his suspicion is correct, not that it is a work around for you to use 😃

I have a fix for this issue - will send a PR today.

Whoops - looks like I spoke too soon. I just ran npm run android instead of npx react-native run-android --variant=release. Debug variant works, but trying to build a release is still broken.

Can confirm that a fresh project compiles and runs correctly! 🎉

Thank you for posting this @micahlt… I almost give up on learning react native… changing the folder name works for me

You’re welcome! Best of luck with your continued learning. Hopefully someone will resolve this in the RN codebase soon!

Sorry if that comment sounded passive-agressive! I’ve already gotten my project to work in another folder on my machine. Just clarifying to @sandisahdewo that this issue isn’t high priority. Thanks for your response to this issue!

Apparently this isn’t high priority, even though it fully breaks RN on any modern Windows machine (since Windows Setup automatically creates a home folder with a space in it

I understand that this is frustrating for you @micahlt but in this case there is a viable workaround which is the one suggested (also I can totally recommend to take the source code in your source root as Windows is not doing great at handling long paths). We have several other bugs/build issues on Windows that are not having a workaround.

Feel free to send a PR or do some investigation for this issue, it will be really appreciated.