BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61 on Apple Arm

To resolve the error "BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61 on Apple Arm," you can try the following steps:

  1. This error typically occurs when you are trying to run or build a Java application with a class file compiled for a newer Java version than what is supported by your current Java runtime.
  2. First, ensure that you have the appropriate JDK (Java Development Kit) installed on your system. You can download and install the latest version of OpenJDK compatible with your system architecture from the official website.
  3. Once you have installed the correct JDK, ensure that your Java environment variables (like JAVA_HOME) are correctly set to point to the JDK installation directory.
  4. Next, check the Java version used for compiling your source code. If it's higher than the version supported by your current JDK, you need to either downgrade your source code's Java version or upgrade your JDK to a version that supports the higher class file version.
  5. If you're using a build tool like Gradle or Maven, make sure your build configuration specifies the correct Java version for compilation.
  6. If you're using an IDE like IntelliJ IDEA or Eclipse, ensure that the project settings are configured to use the correct JDK version.
  7. After making these changes, rebuild your project and run it again to see if the error persists.
Gradle, BUG! BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 64

"I switched to Gradle version 8.1.1. I'm not sure why it worked before, but at least it's working now!"

"I resolved my issue by changing buildToolsVersion = "33.0.0" to buildToolsVersion = "32.0.0". After saving and running, the build was successful."

"If you encounter the same issue, you should update the Gradle version; there's no need to alter the JDK version."

BUG! Exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version

To address the issue quickly, you can change the Java version by modifying org.gradle.java.home in gradle.properties or adding this line:

# android/gradle.properties

Before making this change, ensure you download the appropriate version of Java. For instance, you can download Liberica JDK here.

This option is convenient because you may already have Java installed, albeit not the correct version. This way, the global Java version remains untouched, avoiding changes to environment variables, etc.

Alternatively, you can change the Java version in the Android Studio setup:

Preferences → Build, Execution, Deployment → Build Tools → Gradle

According to the compatibility table above, you can also adjust the Gradle version:

# path: android/gradle/wrapper/gradle-wrapper.properties

For instance, for Java 11, the Gradle version must be 5.0 or higher.

If you already have Java installed, you can verify its version using the command:

java -version

"I encountered the same issue, and what solved it for me was opening the Android folder within the project. This process configures a few missing elements specific to Flutter projects when opening a generic one.

To do this:

File > Open > Select 'Android' inside your project folder

"Initially, I installed JDK using brew install java, which apparently wasn't compatible with my current Gradle version. So, I took the following steps:

  1. Uninstalled Java first using: brew uninstall java
  2. Installed either JDK 8 or JDK 11 from Azul.
  3. Installed Gradle using gradle-6.9-all.zip.

"I found a way to resolve this error without altering the locally installed Java version or Gradle setup. Here's what worked for me:

  • If you're developing a Flutter project and encountering this error, navigate to File -> Close Project.
  • Then, reopen the project from the 'android' folder (skip this step if you're dealing with a pure Android project).
  • Gradle might automatically detect the issue and initiate a check. This process may take some time. After it completes, you may receive upgrade steps in an upgrade assistant window at the bottom of the screen, alongside logcat, build, terminal, etc. Accept and execute these steps.
  • If Gradle doesn't seem to address the issue automatically, open the Project Structure tab.
  • Select the latest Gradle version available without the suffix '-rc' (avoiding release candidates, as they're often unstable).
  • Adjust the JDK version used by Gradle by navigating to Gradle (sidebar on the right of the window) -> Wrench Icon -> Gradle Settings. Choose a compatible JDK version according to the Gradle project's documentation, as specified here. Currently, the latest stable Gradle version is 7.4 with a maximum supported JDK version of 17.
  • Be cautious with the Android Studio version; ensure compatibility with Gradle.
  • Tested on MacBook Air M1 running macOS Monterey 12.2.1."