20

I have react native version 0.42.0. My project was working fine with this.

Recently I upgraded to react-native version 0.43.1. and now when I do

react-native run-android

I am stuck with the 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, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

I have followed the instruction for upgrading from https://facebook.github.io/react-native/docs/upgrading.html

I googled the issue. Gone through the following links none of it worked for me.

  1. Could not find or load main class org.gradle.wrapper.GradleWrapperMain

  2. Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain

  3. How/when to generate Gradle wrapper files?

any kind of help/guidance will be helpfull for me.

Chisko
  • 3,092
  • 6
  • 27
  • 45
chetan
  • 953
  • 3
  • 12
  • 20

5 Answers5

11

Please check your gradle-wrapper.jar from gradle/wrapper folder.

I got the same error as you and I changed the jar with complete one.

I also changed one line in the gradle-wrapper.properties file with *distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip, gradle will download itself.

Chiller
  • 9,520
  • 2
  • 28
  • 38
Mabel Eain
  • 159
  • 6
  • gradle wrapper.jar file is missing for me, what I did copied gradle wrapper.jar file from another project. – Rafiq Jan 25 '23 at 04:42
8
react-native upgrade

Running this command might fix your issue. In my case, it did. But make sure to have a backup of Android and iOS folder in case you modified it.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Akhilesh Sinha
  • 861
  • 12
  • 20
  • Running `react-native upgrade` worked for me in that I just had to rebuild the gradle-wrapper.jar file. This can be done by keeping all the existing files (n) when upgrading react-native when prompted to use or replace existing version. – ppak10 Feb 03 '19 at 16:18
3

I fixed this issue doing these two simple steps:

1) Delete Android and iOS folders

2) Execute the next line

react-native eject

3) Run!

react-native run-android
MattNT
  • 47
  • 2
2
  1. Check your gradle-wrapper.jar file size from ~\android\gradle\wrapper , available jar file size is 49 KB

  2. Update your gradle-wrapper.properties file distributionUrl = https://services.gradle.org/distributions/gradle-2.10-all.zip

  3. Add task wrapper(type: Wrapper) { gradleVersion = '2.10' } on build.gradle

  4. Again, run react-native run-android. If you get this error:

     * What went wrong: Execution failed for task ':app:mergeDebugResources'.
     > Some file crunching failed, see logs for details ,
    

    please add build.gradle with:

    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"
    
        aaptOptions {
            cruncherEnabled = false
            useNewCruncher = false
        }
    
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Mabel Eain
  • 159
  • 6
0

You probably don't have gradle setup in your environment. You can follow below link to configure gradle and then you can run gradle wrapper again.

Follow the instructions mentioned in below link. https://gradle.org/install/#manually

Karzan
  • 1
  • 1