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

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?

This question is related to java android android-studio

The answer is


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


When I tried "react-native run-android" I was receiving errors "Could not initialize class org.codehaus.groovy.runtime.InvokerHelper" + "Failed to install the app. Make sure you have the Android development environment set up"....

Solved it by updating the gradle in Android Studio. When I opened my project in Android Studio it showed a message asking to update Gradle, and I just clicked.


(Solution) I tried my first flutter app in android studio , i was getting same error " Could not initialize class org.codehaus.groovy.runtime.InvokerHelper"

open build.gradle and update dependencies

    classpath 'com.android.tools.build:gradle:4.0.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

or just hover over com.android.tools.build:grandle:(your-version)


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


  1. Go to \android\gradle\wrapper\gradle-wrapper.properties.
  2. Update the installing distribution version (all.zip) of Gradle in distributionUrl. As an example for Gradle version 6.8:

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


In gradle-wrapper.properties file, updating the Gradle to 6.3 solved the problem on Mac OS Catalina

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


The problem in my case was in the discrepancy between the Gradle version installed globally and the one required by React Native. To fix it, I had to update the folder android/gradle/wrapper from the current 6.5 RN version from GH.


I get this error when I open a new project with VS Code & Flutter. I solved the problem by editing the gradle.build and gradle-wrapper.properties files.

Edit android>build.gradle like this:

dependencies { classpath 'com.android.tools.build:gradle:3.5.0' classpath 'com.google.gms: google-services: 4.3.3' //add this line classpath "org.jetbrains.kotlin: kotlin-gradle-plugin: $ kotlin_version" }

Edit gradle-wrapper.properties

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


For me the solution was to upgrade the gradle version to 6.3 from the android project structure (java 14.0.1 is already installed on my pc).


When you upgrade to the latest version of the gradle in the gradle-wrapper.properties file i.e. distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip please do not forget to change the gradle version in the build.gradle file as well

wrapper {
    gradleVersion = '6.6.1'
}

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"

I fixed it just by editing the gradle-wrapper.properties file.

You must go to the project folder, then /android/grandle/wrapper/gradle-wrapper.properties. In DistributionUrl, change to https \: //services.gradle.org/distributions/gradle-6.4.1-all.zip.


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

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

../android/gradle/wrapper/gradle-wrapper.properties


I'm using Pop OS 20.04 and I have Java versions 8, 11 and 14 installed on my notebook.

This error was happening to me when version 14 was standard.

When I switched to using version 11 as the default, the error no longer occurred.

sudo update-alternatives --config java

It is not enough to change distributionUrl in gradle-wrapper.properties, you also need to change gradle version in your project structure.

  1. Go to gradle-wrapper.properties and change:

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

  1. Go to Android studio -> file -> project structure

Change gradle verison to 6.8 or whatever verison you selected that is compatible with your jdk.


In my case problem was that my version of gradle was incompatible with jdk14, but despite in project structure dialog was selected 8jdk, it was necessarily to set jdk home for gradle separately in gradle.propperties

org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home

I face this issue when I was Building my Flutter Application. This error is due to the gradle version that you are using in your Android Project. Follow the below steps:

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

Now Save the File (Ctrl + S), Go to the console and run the command

flutter run

It will take some time, but the issue that you were facing will be solved.


  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)

I also had the same problem and and it looks like this problem is due to the gradle version in the project directory

  • This is the version of my jdk:
openjdk version "15-ea" 2020-09-15
OpenJDK Runtime Environment (build 15-ea+32-Ubuntu-220.04)
OpenJDK 64-Bit Server VM (build 15-ea+32-Ubuntu-220.04, mixed mode, sharing)
  • Please check gradle whether it is installed. This is the version of my gradle:
------------------------------------------------------------
Gradle 6.8
------------------------------------------------------------

Build time:   2021-01-08 16:38:46 UTC
Revision:     b7e82460c5373e194fb478a998c4fcfe7da53a7e

Kotlin:       1.4.20
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          15-ea (Private Build 15-ea+32-Ubuntu-220.04)
OS:           Linux 5.4.0-65-generic amd64
  • Then open the gradle-wrapper.properties file in your project folder, in the folder: project name/android/gradle/wrapper/gradle-wrapper.properties

  • Change the gradle version. Here I changed the gradle version to 6.5

The video version can be seen here: https://www.youtube.com/watch?v=mcclcscUpV0


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to android-studio

A failure occurred while executing com.android.build.gradle.internal.tasks "Failed to install the following Android SDK packages as some licences have not been accepted" error Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util This version of Android Studio cannot open this project, please retry with Android Studio 3.4 or newer WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Flutter plugin not installed error;. When running flutter doctor ADB.exe is obsolete and has serious performance problems Android design support library for API 28 (P) not working Flutter command not found How to find the path of Flutter SDK