32

I moved my Android Studio project from one computer to another computer and now I get this error:

"Unsupported class file major version 61" .

enter image description here

How can I fix this?

Ola Ström
  • 4,136
  • 5
  • 22
  • 41

5 Answers5

30

With the help of @Robert answer,
I found out that the problem was with JAVA 17 and that the Gradle JDK in use was:
Android Studio java home version 17.0.1

I changed it to:
Android Studio default JDK version 11.0.10

enter image description here

Then everything worked like before...

You'll find the Gradle Settings under File > Project Structure...
enter image description here

...or through the Toolbar button: Project Structure...
enter image description here

Then click the Gradle Settings link. enter image description here

Ola Ström
  • 4,136
  • 5
  • 22
  • 41
  • 1
    Strom I am using the JDK version 11.0.15 but still, I couldn't able to download the library and the compiler showed the error "Unsupported class file major version 61". is there any specific version I need to use for downloading the library? – manoj May 05 '23 at 07:43
  • That's because by default, Flutter uses Android Studio's embedded JDK, which in your case is Java 17 – FDuhen Aug 31 '23 at 06:46
14

class file major version 61 means that the class file you are trying to load has been compiled by Java 17 or higher and can only by used by Java 17+.

The Android toolchain only supports classes compiled for Java 11 (if the project is properly configured). So there is something wrong with the library you are trying to load.

As you don't give any details in your question what you are trying to do, it is impossible to give you a more detailed answer.

Pang
  • 9,564
  • 146
  • 81
  • 122
Robert
  • 39,162
  • 17
  • 99
  • 152
9

Step 1:

  • Change version on 'gradle-wrapper.properties' file

'distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip' to 'distributionUrl=https://services.gradle.org/distributions/gradle-7.6-all.zip'

Step 2:

  • In gradle.properties file remove this line 'org.gradle.java.home'

Step 3:

  • In android/build.gradle file:

    buildscript {
      ext.kotlin_version = '1.7.21'
      dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
      }
    }
    
starball
  • 20,030
  • 7
  • 43
  • 238
shraddha patel
  • 628
  • 4
  • 12
0

for mac users, please follow this:

download and install java 11 from here

edit your zshrc file with this:

export JAVA_HOME=$(/usr/libexec/java_home)

open terminal and execute :

cd /Applications/Android\ Studio.app/Contents/jre
ln -s ../jre jdk
ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk

Now run flutter doctor -v

MUHAMMED IQBAL PA
  • 3,152
  • 2
  • 15
  • 23
0

For those ending up on this thread after upgrading to a newer version of Android Studio, here is the official documentation to fix your issue :
https://docs.flutter.dev/release/breaking-changes/android-java-gradle-migration-guide

You're having this issue because Flutter is, by default, using Android Studio's embedded JDK Version. Your best solution here is to embrace the new version of the JDK and to upgrade Gradle accordingly

FDuhen
  • 4,097
  • 1
  • 15
  • 26