Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve (Could not initialize class org.codehaus.groovy.reflection.ReflectionCache) issue in react native

$ npx react-native run-android info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag. Jetifier found 864 file(s) to forward-jetify. Using 4 workers... info Starting JS server... info Launching emulator... error Failed to launch the emulator. Reason: Could not start an emulator within 30 seconds. warn Please launch an emulator manually or connect a device. Otherwise, the app may fail to launch. info Installing the app...

FAILURE: Build failed with an exception.

  • What went wrong: Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1m 23s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details. Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

  • What went wrong: Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1m 23s

at checkExecSyncError (child_process.js:629:11)
at execFileSync (child_process.js:647:13)
at runOnAllDevices (E:\work\react-native\AwesomeProject1\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:39)
like image 203
Gokul Krishnan Avatar asked Mar 25 '20 07:03

Gokul Krishnan


People also ask

How to solve Could not initialize class org?

This Error occurs when the gradle version you used is not compatible on your environment, so you just need to update your gradle version to latest Gradle Versions, just go to: /android/gradle/wrapper/gradle-wrapper. properties to your project file.

Could not initialize class gradle?

This error occurs might be you use Gradle as the build system and JDK14 and the Gradle version is old. Thats why you are facing this error. So that just change Change distributionUrl in gradle-wrapper. properties and your error will be solved.


Video Answer


3 Answers

I think I had the same issue. After installing RN (May 20th, 2020), I bumped into this error. I found this solution on https://github.com/gradle/gradle/issues/10248.

In short:

  1. Go to /android/gradle/wrapper/gradle-wrapper.properties file in your RN project

  2. Find this line that starts with distributionUrl. Change the gradle version into gradle-6.3-all.zip.

In my project, it was:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip

and I changed it into:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

That's it.

like image 130
Asad S Avatar answered Oct 22 '22 11:10

Asad S


I had the same error on Mac OS and React Native v0.62.

Apply these instructions correctly: React native environment setup

Adding this variable solved my problem:

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"

like image 98
behzad rabiei Avatar answered Oct 22 '22 12:10

behzad rabiei


In the React Native version 0.62.x even the initialized application is not ready for a development build.

I change the Gradle version to the latest and I could to have a clean build, so change this file:

// this file => /android/gradle/wrapper/gradle-wrapper.properties

from:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip

to:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip

Pay Attention: The latest version of the Gradle for my time is 6.5. when you are reading this answer please check this link to see the latest version number of the Gradle.

Update Aug 15, 2022

7.5.1

like image 20
AmerllicA Avatar answered Oct 22 '22 11:10

AmerllicA