I'm trying to do the Android tutorial for React Native, but I'm hitting a wall. All of the requirements for React Native to work are good to go, and I've followed the Android Setup instructions.
I do not have a .bashrc, so I made one and put export ANDROID_HOME=/usr/local/opt/android-sdk
in there, but realized when I did echo $ANDROID_HOME
, I got nothing in return. I also don't have a .profile, so I added it to my bash_profile, and it now returns the path with echo.
I have installed
as well as
I installed the Intel HAXM kernel extension and created an AVD using the same parameters shown in the setup instructions.
I then started the emulator for the device I created, opened a new tab in the terminal and ran react-native run-android
, and that's when I hit the error.
Starting JS server...
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.
I have created two different React Native projects with just the skeleton, and I get the error with both, which is making me believe I'm doing something wrong. Has anyone else run into this error or have any idea what might be going on?
Note: It runs fine iOS-wise with XCode
Update:
So someone else sent me a new React Native project that they created on their machine. I downloaded and unzipped it in my Downloads folder. After opening it, I npm install
ed. I then started the emulator and ran react-native run-android
. It worked. So I tried the same thing with the same file in the folder that it should be in. And then I got the error. So it seems that it might have something to do with my environment? In both of these folders, node and npm versions are the same (node v4.1.0 and npm 2.14.5).
Cause and Solution of this error: The common reason of this error is that something related to gradle wrapper is deleted and most probably it is the gradle-wrapper. jar file. You can check this file in gradle/wrapper/gradle-wrapper. jar path of your project.
You can resolve this error by copying gradle-wrapper. jar from your previous projects under /android/gradle/wrapper folder and putting it in the /android/gradle/wrapper folder of the current project. You can also use the following link to download the gradle wrapper file if needed.
Run react-native upgrade It worked for me as I faced this issue at the initial stage. I was able to create the project but due to this org.gradle.wrapper version issue, I was getting the same error.
In case you have faced this issue in the middle of the project, take the backup of your android and ios folder before running the above command.
You may need to generate the gradle wrapper files by running gradle wrapper
at the project root. See How/when to generate Gradle wrapper files?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With