18
votes

I am trying to build and run react native application in my phone. I tried with Getting Started and it's working fine. I do the following to run

  1. cd AwesomeProject
  2. react-native start
  3. Open a new tab in terminal
  4. curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"

  5. react-native run-android

and it runs in my android phone.

Now I am trying to run a project from GitHub, I did the following

  1. git clone https://github.com/h87kg/NavigatorDemo.git
  2. cd NavigatorDemo
  3. react-native start

I get Command 'start' unrecognized. Did you mean to run this inside a react-native project? error. What should I do to run this project ? Any help is appreciated. Thanks in advance.

Update

After installing dependencies npm install I am able to run the server. Now when I try to run react-native run-android I get the following error

JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Could not install the app on the device, see the error above.
5
Not an answer but I really never used start command. After cd into project directory i just do react-native run-android or run-ios :S . Oh yeah and if its other's project normally you have to npm install the dependencies first too.cjmling
yes we don't need to run start if it starts automatically, yes i have updated the questionSaahithyan Vigneswaran
@Saahityan , not sure what its called but close any "other" existing react packager terminal before running new project.cjmling
@cjmling, how do I stop, what is the command or u mean ctrl+cSaahithyan Vigneswaran
I normally just simply close the GUI screen.cjmling

5 Answers

18
votes

Did you install node modules? try npm install

  1. git clone https://github.com/h87kg/NavigatorDemo.git
  2. cd NavigatorDemo
  3. npm install
  4. react-native start
14
votes

The problem is that the gradlew file in the android folder isn't executable anymore because you cloned it from a git repo.

Basically, when you do react-native run-android, It does a lot of thing which includs running commands for you such as cd android && ./gradlew installDebug. right there, it tries to execute the gradlew, but can't, cause the file isn't executable. which is why you get that error.

just cd into the android folder, and do chmod +x gradlew.

1
votes

I have found the solution, this is how I got it working and sharing it with others who are facing the same problem

  1. Create a folder called assets inside android/app/src/main/
  2. Copied gradle folder inside android/ from my existing working project AwesomeProject
  3. (cd android && ./gradlew installDebug)
  4. curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
  5. react-native run-android

These are the exact steps I followed, hope it helps.

1
votes
  1. Copy gradle folder inside android/ from my existing working project root
  2. Go to android directory and run this: ./gradlew installDebug
  3. Now copy your gradle folder back to the original location.

This is the solution that worked for me. Do not forget to close the node server during the process.

0
votes
npm install react-native-fs --save --legacy-peer-deps

This will fix your issue