Android Studio Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

213,170

Solution 1

I faced this issue because of lower version of Jdk. Previously I installed Jdk 1.7 and Android Studio 1.5.1, I got this issue. If you install Android Studio 1.5.1 or above JDK 1.8 required

So Installing JDK 1.8 solved this issue.

Solution 2

Please make changes as per below to resolve this error.

Install Java SDK version: 14 or above.

JDK Download link: https://www.oracle.com/java/technologies/javase-jdk14-downloads.html

In gradle-wrapper.properties please use grade version 6.3 or above.

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

Solution 3

  1. This is because of the gradle version.

  2. Go to: gradle/wrapper/gradle-wrapper.properties.

  3. Change a version of the course by this:

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

The console outputs:

Welcome to Gradle 6.3!
Here are the highlights of this release:
 - Java 14 support
 - Improved error messages for unexpected failures
For more details see https://docs.gradle.org/6.3/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)

Solution 4

First watch this and try reinstall - https://youtu.be/trHinrIm6DM

After if you get "Could not initialize class org.codehaus.groovy.runtime.InvokerHelper"

1.install Java SDK 14 and update env path.

2."[Your RN or Flutter Project Folder]\android\gradle\wrapper\gradle-wrapper.properties" this file edit as ...(upgrade gradle version)

#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip

3.run gradlew in cmd path "[Your RN or Flutter Project Folder]\android\"

4.it takes time.after if shows "BUILD SUCCESSFUL" you can "flutter run" in ur project folder

Yeah It's work 👍

Solution 5

What was helpful for me (MacBook):

  • first go to File -> Invalidate Caches / Restart -> Invalidate and Restart
  • then check the value of JAVA_HOME enviroment variable, by calling echo $JAVA_HOME (it should be equal to "/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home")
  • if it is not, change its value by calling export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
Share:
213,170

Related videos on Youtube

Author by

sm_

Love to share knowledge..

Updated on July 19, 2022

Comments

  • sm_ 5 months

    I am new in Android Studio. After setup, When I am trying to import an application I am getting that error So that gradle not able to build.

    Error:Could not initialize class org.codehaus.groovy.runtime.InvokerHelper

    I checked that my classpath setting for Java is fine. I am running Windows OS. Does anyone know the source of the error?

    • Paul
      Paul almost 7 years
      Did you check your "JAVA_HOME" variable?
  • Bruno de Oliveira over 2 years
    Updating the Gradle from 6.0.1-all to 6.3-all solved the problem on Mac OS Catalina, tks. React-native build by the way.
  • Fathi Osama over 2 years
    Thanks a lot, i couldnt find a solution anywhere else.
  • Abhimanyu Rathore over 2 years
    I was beginner in react native and was scratching my head from so long to run Android device !! .Y ou are amazing Man !!! you saved my time and thanks that you have a great attitude to help others like this clean information !!
  • Riley Fitzpatrick over 2 years
    I am using Java 14. with Gradle 6.4 but the problem still exists for me.
  • Jeaf Gilbert
    Jeaf Gilbert over 2 years
    BEST ANSWER, why is this not included in the ReactNative init.
  • Maher Abuthraa
    Maher Abuthraa over 2 years
    this worked with me "distributionUrl=https\://services.gradle.org/distributions/‌​gradle-6.3-all.zip"
  • Chagai Friedlander
    Chagai Friedlander over 2 years
    thanks, this really helped me! why is this happening? could I use a lower gradle version(perhaps also a lower java version) and still get it to work?
  • Spikatrix
    Spikatrix over 2 years
    Switching to Java 8 worked for me (I didn't have 11 installed). Thanks!
  • Michael Ashefor over 2 years
    command should be ./gradlew not gradlew . Everything else works fine
  • Mohammad
    Mohammad over 2 years
    how about the old projects? with distribution 5.~.zip and jdk 14
  • locropulenton
    locropulenton over 2 years
    Thanks! This works for me given that I am in a react native project and JAVA 14 / Open JDK!
  • Mahad Ahmed about 2 years
    I'm on java version "15" 2020-09-15 and this worked for me on MacOS Catalina.
  • Ahmed Elshaer about 2 years
    This is actually worked with me without the need to update wrapper version, the case that I did a fresh install on my macOS and installed a lot of things and this could have changed the JAVA_HOME and cause this issue, thanks a lot
  • dilantha111
    dilantha111 about 2 years
    Thanks this helped. Not sure why this was not yet selected as the accepted answer.
  • VtoCorleone about 2 years
    Welcome to Stackoverflow and great contribution!
  • Shariful Islam Mubin
    Shariful Islam Mubin about 2 years
    Super! Works like a charm in Flutter!!
  • sudonitin about 2 years
    This worked for me. But it sort of gets reset on every bootup. How can I make this change permanent?
  • Soumya Boral
    Soumya Boral about 2 years
    where can I get gradle-wrapper.properties file please ?
  • bongtoi about 2 years
    You can get it at path "YOUR_PROJECT/gradle/wrapper/gradle-wrapper.properties"
  • Pradap Pandian
    Pradap Pandian about 2 years
    This saved my life
  • jakub-adamczewski about 2 years
    Hey @sudonitin, check there to see how to save enviroment variables permanently: medium.com/@youngstone89/…
  • Anchal Ajay about 2 years
    Updating the Gradle from 5.6.2-all to 6.5-all solved the problem on Windows, For Flutter
  • dılo sürücü
    dılo sürücü almost 2 years
    switched 11 version and worked for me (pop-os)
  • dragon788
    dragon788 almost 2 years
    This is huge because you DO NOT have to go through the trouble of installing Java if you have Android Studio. See also stackoverflow.com/a/48957460 for shell config to set some things automatically.
  • Shivam Jha
    Shivam Jha over 1 year
  • Mike S.
    Mike S. over 1 year
    I did the same. In my case, it didn't fix the issue.
  • Mike S.
    Mike S. over 1 year
    This is the same answer that @josileudo provided.
  • Mike S.
    Mike S. over 1 year
    For react native, it's slightly different: YOUR_PROJECT/android/gradle/wrapper/gradle-wrapper.propertie‌​s
  • negrotico19
    negrotico19 over 1 year
    This is not working for me because the Path Please set the JAVA_HOME variable in your environment to match the location of your Java installation., However following this link: stackoverflow.com/a/19663996/4696051 allowed me to find the correct Java Home Path in MacOs Catalina /usr/libexec/java_home
  • Pentagura over 1 year
    Thank you, you save my live
  • anie
    anie over 1 year
    you saved my day, just for me required a further step which is rebuild gradle in android studio in mac OS.
  • Umer Waqas Flutter Developer over 1 year
    export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"

Related