npm use in build.gradle when using Android Studio
See original GitHub issueAn error is being thrown by the use of npm in this line of the build.gradle:
version = "npm --silent run get-version".execute(null, projectDir).text.trim()
I am using this in a React Native project. I typically build from the command line but attempted to build in Android Studio and the build fails with this error since it can’t find the npm executable:
Cannot run program "npm" (in directory "/Users/<directory>/node_modules/realm/android"): error=2, No such file or directory
The default path for a GUI application like Android Studio on macOS is:
/usr/bin:/bin:/usr/sbin:/sbin
In my case, npm is in /usr/local/bin
installed through homebrew.
If I change the command to a full path then it builds correctly:
version = "/usr/local/bin/npm --silent run get-version".execute(null, projectDir).text.trim()
Any suggestions for handling this in the publish_android_template instead of me manually correcting this?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:20
- Comments:26 (7 by maintainers)
Top GitHub Comments
Hi @davidstoker
Android Studio doesn’t inherit the environment variables you defined in your shell. we have similar problem in realm-java where we use
launchctl setenv
to work around the issue.In your case a quick work around, is to start Android Studio from the shell (ex: on OSX)
~/Applications/Android\ Studio.app/Contents/MacOS/studio&
this will inherit thePATH
containingnpm
Cheers
Was seeing this problem on windows even though npm was in the path. Was able to resolve the issue by adding the npm file extension (see below).