194

EDIT: I am uncertain which steps I took to resolve this problem, and am no longer seeing this error message so I cannot test the solutions below. Please try them individually as different answers seem to be working for different people.

The iOS version works fine, but running Android Studio on my Mac I get the following Gradle Build error (paraphrased):

:ReactNative:Running ‘[node, -e, console.log(require(‘react-native/cli’).bin);]’ command failed.

- Where:
Script ‘/Users/…/Desktop/…/node_modules/@react-native-community/cli-platform-android/native_modules.gradle’ line: 154

- What went wrong:
A problem occurred evaluating script.
> Cannot run program “node”: error=2, No such file or directory

Caused by: java.io.IOException: Cannot run program “node”: error=2, No such file or directory

I've tried so many things:

I used to be able to still run yarn android in Terminal, but even that has stopped working.

1

39 Answers 39

1
2
0

You should update Android Studio to latest version. It does work for me.

Sign up to request clarification or add additional context in comments.

Comments

0

You can upgrade your Android studio to 2021.3.1. Its working for us.

Comments

0

I was also facing issue on Mac(Monterey 12.6.1).I don't know what was the exact reason but I've just upgraded my Android studio artic fox to Android Studio Dolphin | 2021.3.1 Patch 1. And surprisingly my issue is resolved.

Comments

0

If you're using nvm, this can work: https://stackoverflow.com/a/69066155/10047450

But you need to run nvm use [version] (or just nvm use if you have an .nvmrc configured) in the terminal before launching android studio.

Comments

0

I had the same issue on React Native, with newArch enabled, I tried a lot of solutions, but finally this worked for me:

I added the node path into the file android/app/build.gradle setting the nodeExecutableAndArgs property like this:

import groovy.json.JsonSlurper

project.ext.react = [
    nodeExecutableAndArgs: [getNodePath()]
]

def getNodePath() {
    def process = "which node".execute()
    process.waitFor()
    def nodePath = process.in.text.trim()
    if (!nodePath) {
        throw new GradleException("Node.js executable not found in PATH. Please ensure Node.js is installed.")
    }
    return nodePath
}

This solution ensures that Gradle dynamically retrieves the correct path to node during the build process.

Comments

0

I ran into the same issue on Mac. I tried to open Android Studio from the terminal and I also tried to reinstall it. None of them could fix the issue. Finally, I switched the Gradle JDK version through settings -> Build, Execution, Deployment -> Build Tools -> Gradle. I switched it to the openjdk17 that I installed by myself, and the problem was solved.

Comments

0

I simply had to restart my computer and then it worked again. I didn't have to change anything. It just automatically downloaded a bunch of stuff first:

Starting Gradle Daemon...
Gradle Daemon started in 609 ms
> Task :gradle-plugin:pluginDescriptors
> Task :gradle-plugin:processResources
> Task :gradle-plugin:compileKotlin
> Task :gradle-plugin:compileJava NO-SOURCE
> Task :gradle-plugin:classes
> Task :gradle-plugin:jar
> Task :gradle-plugin:inspectClassesForKotlinIC

> Configure project :app
Reading env from: .env
app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'androidx.room:room-compiler:2.6.1'.

> Configure project :react-native-firebase_app
:react-native-firebase_app package.json found at /myproject/node_modules/@react-native-firebase/app/package.json
:react-native-firebase_app:firebase.bom using default value: 32.7.1
:react-native-firebase_app:play.play-services-auth using default value: 20.7.0
:react-native-firebase_app package.json found at /myproject/node_modules/@react-native-firebase/app/package.json
:react-native-firebase_app:version set from package.json: 18.8.0 (18,8,0 - 18008000)
:react-native-firebase_app:android.compileSdk using custom value: 34
:react-native-firebase_app:android.targetSdk using custom value: 34
:react-native-firebase_app:android.minSdk using custom value: 24
:react-native-firebase_app:reactNativeAndroidDir /myproject/node_modules/react-native/android

> Configure project :react-native-firebase_dynamic-links
:react-native-firebase_dynamic-links package.json found at /myproject/node_modules/@react-native-firebase/dynamic-links/package.json
:react-native-firebase_app package.json found at /myproject/node_modules/@react-native-firebase/app/package.json
:react-native-firebase_dynamic-links:firebase.bom using default value: 32.7.1
:react-native-firebase_dynamic-links package.json found at /myproject/node_modules/@react-native-firebase/dynamic-links/package.json
:react-native-firebase_dynamic-links:version set from package.json: 18.8.0 (18,8,0 - 18008000)
:react-native-firebase_dynamic-links:android.compileSdk using custom value: 34
:react-native-firebase_dynamic-links:android.targetSdk using custom value: 34
:react-native-firebase_dynamic-links:android.minSdk using custom value: 24
:react-native-firebase_dynamic-links:reactNativeAndroidDir /myproject/node_modules/react-native/android

> Configure project :react-native-firebase_messaging
:react-native-firebase_messaging package.json found at /myproject/node_modules/@react-native-firebase/messaging/package.json
:react-native-firebase_app package.json found at /myproject/node_modules/@react-native-firebase/app/package.json
:react-native-firebase_messaging:firebase.bom using default value: 32.7.1
:react-native-firebase_messaging package.json found at /myproject/node_modules/@react-native-firebase/messaging/package.json
:react-native-firebase_messaging:version set from package.json: 18.8.0 (18,8,0 - 18008000)
:react-native-firebase_messaging:android.compileSdk using custom value: 34
:react-native-firebase_messaging:android.targetSdk using custom value: 34
:react-native-firebase_messaging:android.minSdk using custom value: 24
:react-native-firebase_messaging:reactNativeAndroidDir /myproject/node_modules/react-native/android

> Task :prepareKotlinBuildScriptModel UP-TO-DATE
Download https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.4.2/gradle-7.4.2-sources.jar, took 11 s 400 ms
Download https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.9.0/kotlin-gradle-plugin-1.9.0-sources.jar, took 1 s 628 ms
Download https://repo.maven.apache.org/maven2/de/undercouch/gradle-download-task/4.1.2/gradle-download-task-4.1.2-sources.jar, took 147 ms

...

Download https://dl.google.com/dl/android/maven2/androidx/camera/camera-core/1.3.1/camera-core-1.3.1-sources.jar, took 638 ms
Download https://repo.maven.apache.org/maven2/com/stripe/identity/20.52.3/identity-20.52.3-sources.jar, took 438 ms
Download https://dl.google.com/dl/android/maven2/androidx/databinding/viewbinding/8.5.2/viewbinding-8.5.2-sources.jar, took 304 ms

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.5.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 7m 57s
5 actionable tasks: 5 executed

Comments

-1

I got this error in an Expo app after I upgraded Android Studio.

Restarting the entire Mac fixed it.

Comments

-2

If you have a M1 Mac and are using Android Studio:

1 Comment

This is good advice for M1, I found that same JDK as one of the few native options for JDK. But I guess it's not directly relevant to this question.
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.