Issue
When opening or building the Android build folder of a native mobile application in Android Studio on macOS, Gradle sync or build fails with an error indicating that npx cannot be executed or found:
A problem occurred starting process 'command 'npx''
java.io.IOException: Cannot run program "npx" (in directory "..."): error=2, No such file or directoryEnvironment
Native Mobile
Cause
When Android Studio is launched from macOS, it runs in a desktop session that does not automatically load shell initialization scripts (such as ~/.zshrc or ~/.bash_profile).
If Node.js and npx are installed via Node Version Manager (nvm), the binary directory (e.g., ~/.nvm/versions/node/<version>/bin) is only added to the PATH in interactive shell sessions. As a result, Android Studio’s internal process environment lacks npx in its PATH, causing Gradle tasks that invoke npx to fail.
Solution / Workaround
Launching Android Studio from the terminal ensures it inherits the active shell's environment, including the nvm PATH:
- Close Android Studio completely.
Open the terminal and run:
cd /path/to/the/android/project open -a "Android Studio" .- Sync and rebuild the project.
Internal information related
Not Applicable
Additional information
Not Applicable
0 Comments