192

I am trying to use react-native run-android to install my react-native application on an android studio emulator. I have checked with abd-devices that the emulator is available, and I have ran npm-install.

I am using Ubuntu 18.04 with the latest version of android studio, and the latest Pixel 2 XL API 28.

I get the following error:

spawnSync ./gradlew EACCES

Error: spawnSync ./gradlew EACCES
    at Object.spawnSync (internal/child_process.js:998:20)
    at spawnSync (child_process.js:622:24)
    at Object.execFileSync (child_process.js:650:13)
    at runOnAllDevices (/home/user/react/front-end/project/node_modules    /react-native/local-cli/runAndroid/runAndroid.js:299:19)
    at buildAndRun (/home/user/react/front-end/project/node_modules/react-native/local-cli/runAndroid/runAndroid.js:135:12)
    at isPackagerRunning.then.result (/home/user/react/front-end/project/node_modules/react-native/local-cli/runAndroid/runAndroid.js:65:12)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)

I have tried restarting my PC and the emulator several times. Any ideas?

UPDATE: I reinstalled JDK, npm, react-native-cli and android studio. It still gives me the exact same error. Please help.

3
  • Have you tried increasing the count of your inotify watchers? github.com/guard/listen/wiki/…
    – Andrew
    Commented Feb 5, 2019 at 19:51
  • @Andrew Tried it now. It did nothing :( Commented Feb 5, 2019 at 19:56
  • problem is not specific to emulator usage, affects any unix-derived system (tested on Linux, macOS, Windows) works fine on Windows because file modes/ACLs are not relevant on Windows platform. this could be addressed within the rn git repo itself, in that regard accepted answer is a workaround.
    – wilson0x4d
    Commented Apr 3, 2021 at 21:51

10 Answers 10

700

I fixed this problem with:

chmod 755 android/gradlew 

the chmod command sets the permissions of files or directories. https://www.computerhope.com/unix/uchmod.htm

12
  • 7
    fixed the problem successfully. But it would be nice if you explain what it does. Would've been useful to many people i think.
    – AL-zami
    Commented May 6, 2019 at 5:06
  • 4
    @Grez.Kev this command makes gradlew files into executable. Which help code to give a run. This solution saves my hours. Thnx Commented May 10, 2019 at 19:02
  • 2
    I do not have gradlew directory under my android dir, what sould I do?
    – JollyRoger
    Commented Sep 1, 2019 at 12:39
  • 1
    @BlueBot gradlew is not a directory. It's a file (gradle wrapper) that is part of your project. Commented Jan 7, 2021 at 7:33
  • 2
    This definitely worked. But just wondering why this wasn't taken as a precaution for React Native development or mentioned in the docs...
    – 6rchid
    Commented Oct 25, 2021 at 0:37
82

gradlew file permissions should be updated, you can resolve it by changing the permission, run the following command

chmod 755 android/gradlew

it will give (read,write,execute) permission for the user(owner), also (read, execute) for group and other users.

18

It turns out that It's not gradle but it's android/gradlew. run the below command inside the root directory:

$ chmod +x android/gradlew

Now run

$ yarn android            
# OR   
$ npm run android 
# OR
$ npx react-native run-android

You should be good to go.

17

I tried the above solution.but in my case I had to use sudo because of the permission issue. You can resolve it by running the command

sudo chmod 755 android/gradlew

1
  • 1
    Can you explain why you don't use the same path as in the other answers?
    – Nico Haase
    Commented Aug 23, 2019 at 5:58
3

On the first approved answer from @Jinkey, in case you are wondering where to run this command, like in my case on Mac, follow these steps:

  1. In your terminal navigate to your project folder cd <project folder>, make sure the path to your project is correct.
  2. Then once in the folder, run the command by copying and pasting as is chmod 755 android/gradlew
0
1

sudo chmod 755 android/gradlew works perfectly fine for this issue in mac!

1

Go to the react native cli project directory then run this command below :

sudo chmod 755 android/gradlew 

then run the command:

npx react-native run-android

then start the metro (if it is not started automatically) by following command:

npx react-native start
1

For me it was go to folder one above your project and run chmod -R a+rwx nameOfTheProject/ or if that doesn't work chmod -R 777 nameOfTheProject/

Solution found on this link https://edwardbeazer.com/how-to-fix-this-error-spawn-eacces/

0

On MacBook Air M1 chip chmod 755 android/gradlew works great. Also add the below line in the android/local.properties file.

sdk.dir = /Users/YourUserNAME/Library/Android/sdk
-1

FIXED

Just run this:

sudo chmod 755 android/gradlew
1
  • This has already been mentioned in other answers, such as this one.
    – Eric Aya
    Commented Mar 1, 2023 at 9:34

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.