<-- Back

Gradle build fails in Android Studio: npx: command not found

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 directory

Environment

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:

  1. Close Android Studio completely.
  2. Open the terminal and run:

    cd /path/to/the/android/project
    open -a "Android Studio" .
  3. Sync and rebuild the project.

Internal information related

Not Applicable

Additional information

Not Applicable

Have more questions? Submit a request

0 Comments

Article is closed for comments.

To provide feedback, please open a ticket here. Don't forget to include the article's URL along with the feedback you would like to provide.