Nathanael
Nathanael

Reputation: 1001

Android Studio setting node directory for build (Cause: error=2, No such file or directory)

My project build fails because it's using the incorrect directory to run Node. How do I go about setting the Node directory for these compile-time tasks?

The specific task is:

app:recordFilesBeforeBundleCommandDebug

And the related error:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:recordFilesBeforeBundleCommandDebug'.
Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'node''
Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'node'
Caused by: java.io.IOException: Cannot run program "node" (in directory "/Users/me/Code/appname/android/app"): error=2, No such file or directory
Caused by: java.io.IOException: error=2, No such file or directory

Upvotes: 18

Views: 19151

Answers (5)

Manish Arora
Manish Arora

Reputation: 607

Find the node path in your system using command

which node inside terminal Then open app/build.gradle and add this line

ext {    
    react = [
        nodeExecutableAndArgs:  ["Node path from the above command"]
    ]
}

After that it may ask to upgrade kotlin version then add this in build.gradle

buildscript {
        ext {
            kotlinVersion = "1.6.0"
        }
    }

Upvotes: 1

batman
batman

Reputation: 366

It is a known bug for the environment:

  • Apple chip M1
  • Android Studio arctic fox 2020.3.1 Patch 3

Upgrade to Gradle version 6.9 or above in the gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-all.zip

https://docs.gradle.org/6.9/release-notes.html

Upvotes: 24

Urska Krivc
Urska Krivc

Reputation: 844

I am running Android Studio on MacOS and following worked for me: Yoruba's answer above and starting the application from Terminal with open -a "Android Studio.app"

Upvotes: 35

Antonio Junior
Antonio Junior

Reputation: 91

I had the same problem and solved by installing node.js again because the react was not able to find it.

Upvotes: 0

Yoruba
Yoruba

Reputation: 2780

Add this to the build.gradle if you use React-Native

ext {    
    react = [
        nodeExecutableAndArgs:  ["/usr/local/bin/node"]
    ]
}

Upvotes: 13

Related Questions