my case, on Windows 10, my JAVA_HOME was set to JAVA SE 16 C:\Program Files\Java\jdk-16 and when I looked at the release file in java jre in android studio, C:\Program Files\Android\Android Studio\jre\release, I found that the the JAVA_VERSION WAS "11.0.10" (java 11) for short. So I changed the java installation on my PC to Java 11, update JAVA_HOME in my environment variables to point to the new java (C:\Program Files\Java\jdk-11.0.12) and restarted android studio, Then everything worked.

removed the JAVA_HOME path to the JAVA download and changed JAVA_HOME path to the following:

C:\Program Files\Android\Android Studio\jre

this error occurs, this might because you have installed the latest JDK such as JDK 16. You download and install JDK 8 and uninstall JDK 16. Then restart the desktop/laptop and try launch and run flutter run again. 

should be working fine.

Java JDK 16 is the one that seems to lead to this issue try downgrading by downloading a lower version of JDK preferable JDK 8 or 11

To future individuals who will run to this error. Here is the link to download the JDK enjoy your coding experience don't forget to change the path too. https://www.oracle.com/java/technologies/javase-downloads.html

added this line to ./android/gradle.properties for OSX:

org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/Contents/Home

need to update version of Gradle:

  1. go to https://gradle.org/install/ and get info about last version (for now it is 7.1.1)
  2. open gradle/wrapper/gradle-wrapper.properties and change version to last

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

 Windows 10, set the JAVA_HOME environment variable to the JRE for Android Studio. For example:

C:\Program Files\Android\Android Studio\jre

Gradle "Could not open buildscript class cache"

Answer-1

go to location ".gradle\caches\2.0\scripts\build_7l4t45nbnsvdcl79ol8u0beli4\ProjectScript" and remove cache.properties.lock file


Answer-2

xception typically occurs due to corrupted cache files.

Deleting the cache do work in most cases.

Linux

rm -rf ~/.gradle/caches

Windows

Delete the %USER_HOME%.gradle/caches folder