I was working on a local project from scratch which was not on github and it was running successfully. But when i clone a project from github and try to run on android, mostly (not every application cloned from github gives me this error but few big application gives) it gives me error like
Command That I run:
npx react-native run-android
Error that I get:
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
CodePudding user response:
This is because you have to download the gradle files first before running it. Follow the steps and it will definitely run.
- Step 1: Clone the project from github repo.
- Step 2: Open it in any code editor (I prefer VS code).
- Step 3: Install node_modules by
running
npm install
command in terminal. - Step 4: Open android studio and open the react-native-app/android folder inside it.
Note: Android Studio will automatically start downloading the gradle and build it, which you can see in bottom part of android studio.
Step 5: After gradle files are downloaded and build successfully, go back to the code editor and try to run your app again using
npx react-native run-android
Note: If it shows the same error restart your code editor or laptop and it will work like a charm.
CodePudding user response:
make sure you have configure the environment of react native in your machine(desktop/laptop).
follow the link for environment Setup:
https://reactnative.dev/docs/environment-setup after that follow below steps:
- Clone the project from
github
. - cd
projectName
npm
installnpx
react-native run-android