3

"General error during conversion: Unsupported class file major version 63"

I've tried multiple suggestions on here. None have worked. I think I need more of a step-by-step solution because I've tried installing multiple versions of Java (19,16,11), flutter clean, flutter doctor is all good, and I've installed a newer version of Android Studio (just in case). Here is what I see in VSCode:

enter image description here

enter image description here

tazboy
  • 1,685
  • 5
  • 23
  • 39
  • As seen [here](https://en.wikipedia.org/wiki/Java_class_file#General_layout), class file version 63 corresponds to Java 19. If it says that's not supported, then that means you aren't using Java 19. Go back to 19 and make absolutely sure that your IDE is pointing to the correct Java version. Simply installing a bunch of random Java versions doesn't necessarily tell your IDE and other programs to use the new versions. – Silvio Mayolo Feb 07 '23 at 21:06
  • Version 63 is Java 19. Your "build environment" is somehow using an *OLDER* JRE. Q: Are you using VSCode (my preference) , Android Studio or the Flutter CLI to build your Flutter app? Q: What happens if you try the Flutter CLI (in my experience, VSCode build == CLI build)? You should also try a CLI "flutter doctor". – paulsm4 Feb 07 '23 at 21:07
  • @SilvioMayolo I've looked in the settings and I'm not seeing where to point VSCode to use Java 19. Are you familiar with that process? – tazboy Feb 07 '23 at 21:29
  • @paulsm4 Flutter doctor is all good. I'm using VSCode. The project runs but there are two errors in the Android folder. Thoughts on how to fix this? – tazboy Feb 07 '23 at 21:32
  • Look here: https://github.com/flutter/flutter/issues/110807. Try `flutter build apk -v` from a command prompt and tell us what happens. Ensure `JAVA_HOME `is set throughout your environment, and that wherever it's set, it points to your Java 19. Based on the "flutter issues" link above ... you might even consider hacking the JAVA_HOME in your "gradle.dart" (as a last resort). – paulsm4 Feb 07 '23 at 22:41
  • @paulsm4 Here is what prints out as a warning after running `flutter build apk -v`. Runtime JAR files in the classpath should have the same version. These files were found in the classpath: C:/Users/Main/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.5.30/5fd47535cc85f9e24996f939c2de6583991481b0/kotlin-stdlib-jdk8-1.5.30.jar (version 1.5) C:/Users/Main/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.6.10/e1c380673654a089c4f0c9f83d0ddfdc1efdb498/kotlin-stdlib-jdk7-1.6.10.jar (version 1.6) – tazboy Feb 12 '23 at 17:42
  • Q: Did you resolve this? Q: What about [this](https://stackoverflow.com/q/75356399/421195)? – paulsm4 Feb 16 '23 at 03:46

2 Answers2

2

The problem is that somehow, either deliberately or inadvertently, you've built one or more Java files (or you're using one or more 3rd party .jars) with Java 19 ... but your "build environment" is using an older JRE. Hence the Unsupported class file error.

I, too, am using VSCode for my Flutter IDE; and I, too have Android Studio in my environment. Unfortunately, there are constantly new releases for Flutter, for VSCode, for the Android SDK, for Android Studio (with its own embedded Java/Kotlin!) and - last, but not least - for Gradle and the A/S Gradle plugin. Any one of them falling out of sync can break your entire development environment :(

I just tried to rebuild a project that compiled fine a few months ago... and (as expected) the build failed. None of the source change - but I recently upgraded A/S, and that inadvertently broke the Flutter build :(

SUGGESTION:

  1. See if you can identify which Java class or .jar is using Java 19 ... and back it down to an older version.

  2. In parallel, upgrade EVERYTHING in your build environment:

    • flutter upgrade => Flutter 3.7.3, Dart 2.19.2

    • VSCode update, pub upgrade => VSCode 1.751, Dart Code 3.58.0

    • A/S upgrade => Electric Eel 2022.1.1 Patch 1, Gradle Plugin 4.2.2

      Note: Gradle Plugin 4.2.2 => Gradle version => 6.7.1, Default=Java8, AGP dependency 4.2.2

    • A/S Electric Eel gives you java 11... in (new!) directory "c:\Program Files\Android\Android Studio\jbr"

Dharman
  • 30,962
  • 25
  • 85
  • 135
paulsm4
  • 114,292
  • 17
  • 138
  • 190
1

I encountered this error while trying to run Flutter integration tests on Firebase Test Lab. I was able to solve this by updating a few things in Android Studio.

Update the Project's JDK

Open the Android Studio project settings page (File -> Project Settings) and add the newest JDK version.

enter image description here

Update com.android.tools.build:gradle

In android/build.gradle, update the com.android.tools.build:gradle value to the latest version found here.

 dependencies {
        classpath 'com.android.tools.build:gradle:7.4.1'
        ...
    }

Update the gradle distributionUrl

In android/gradle/wrapper/gradle-wrapper.properties, update the distributionUrl property to use the latest Gradle version.

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

Other Useful Tips

  • You can type /usr/libexec/java_home into the terminal to see which version of Java you have installed.

  • You can find the current value of JAVA_HOME by running %echo $JAVA_HOME in your terminal (source).

  • You can update JAVA_HOME by following these steps

Code on the Rocks
  • 11,488
  • 3
  • 53
  • 61
  • The *BEST* solution (if, you happen to be using Visual Studio code for your IDE) is to not rely on Android Studio at *ALL* for your Flutter/Android build environment. – paulsm4 Feb 08 '23 at 22:31
  • in my case, JDK19 with GRADLE7.6 build succeeded – larsien Mar 29 '23 at 08:43