Gradle: Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
Solution 1
change the version of the gradle
edit the file in YOUR_PROJECT/android/gradle/wrapper/gradle-wrapper.properties
and change the version
FROM:
distributionUrl=https://services.gradle.org/distributions/gradle-6.0.1-all.zip
TO:
distributionUrl=https://services.gradle.org/distributions/gradle-6.4.1-all.zip
source: https://github.com/gradle/gradle/issues/10248#issuecomment-633656326
Solution 2
You need to change the Gradle version of your project.
It's mentioned in the official docs: https://reactnative.dev/docs/environment-setup
"If you're using the latest version of Java Development Kit, you'll need to change the Gradle version of your project so it can recognize the JDK. You can do that by going to {project root folder}\android\gradle\wrapper\gradle-wrapper.properties and changing the distributionUrl value to upgrade the Gradle version. You can check out here the lastest releases of Gradle."

reactnative
Updated on December 25, 2021Comments
-
reactnative 12 months
I saw this gradle error: "Could not initialize class org.codehaus.groovy.runtime.InvokerHelper". I have tried multiple ways listed online to fix the issue but no luck. During the debugging, I found weird JVM version.
Installed Java 14 and I have set the path in JAVA_HOME in bash_profile. However, gradle shows JVM 13 version. I am not sure if this cause the error: Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
My java version
java version "14.0.1" 2020-04-14 Java(TM) SE Runtime Environment (build 14.0.1+7) Java HotSpot(TM) 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
Gradle version, but not sure why JVM shows 13
Gradle 6.5 ------------------------------------------------------------ Build time: 2020-06-02 20:46:21 UTC Revision: a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4 Kotlin: 1.3.72 Groovy: 2.5.11 Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019 JVM: **13.0.2 (Oracle Corporation 13.0.2+8)** OS: Mac OS X 10.14.6 x86_64
Gradle error
npx react-native run-android info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag. Jetifier found 960 file(s) to forward-jetify. Using 4 workers... info JS server already running. info Launching emulator... info Successfully launched emulator. 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 3s error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details. Error: Command failed: ./gradlew 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 3s
-
Rebecca Campbell over 2 yearsI had the same issue and this worked for me. Thanks, Pablo!
-
Ουιλιαμ Αρκευα over 2 yearsIndeed you must change it to currently installed version in your system.
-
Abdulkadir Ugas about 2 yearsbro you made my day I was having this error and tried a lot to solve but nothing works this solution works me. you deserve more than thanks
-
Juan Carlos Salinas Ojeda almost 2 yearsThis should be the "Answer". Works for me too.
-
double-beep 12 monthsInstead of posting an image of the official documentation can you paste the text in your answer formatting it accordingly? (use blockquotes and code formatting where needed)
-
Muhammad Ahmed Hassan 12 monthsThe image is just to show where the text is written in the docs. So that, the reader doesn't waste his time.
-
double-beep 12 monthsThen you can add both the text and the image. Keep in mind that images aren't searchable, harder to read on mobile, require more bandwidth and users can't copy-&-paste the text in their code (e.g. as a comment).