Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Android - Could not find or load main class org.gradle.wrapper.GradleWrapperMain

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

  • Android SDK Build-tools version 23.0.1
  • Android 6.0 (API 23)
  • Android Support Repository

as well as

  • Intel x86 Atom System Image (for Android 5.1.1 - API 22)
  • Intel x86 Emulator Accelerator (HAXM installer)

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 installed. 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).

like image 461
KirRogue Avatar asked Sep 22 '15 16:09

KirRogue


People also ask

Could not find or load main class org gradle wrapper gradlewrappermain react native?

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.

Could not find or load main class org gradle wrapper gradlewrappermain flutter?

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.


2 Answers

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.

like image 70
Akhilesh Sinha Avatar answered Oct 24 '22 07:10

Akhilesh Sinha


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?

like image 21
headuck Avatar answered Oct 24 '22 07:10

headuck