Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

An error occurs when trying to build an apk:

FAILURE: Build failed with an exception.
* What went wrong:
Could not open settings generic class cache for settings file 'C:\Ruble\flutter_project\android\settings.gradle'
(C:\Users\Ruble\.gradle\caches\6.7\scripts\1fnwrr8g4rohfp291nvlxj5qe).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61

Using flutter the command to build looks like this - flutter build apk.

This error can occur in Android Studio, Visual Studio Code and other tools where you can build android applications.

Also, whether react native or flutter.

How to fix it?

like image 829
Ruble Avatar asked Nov 19 '25 00:11

Ruble


2 Answers

This is because you are using a Java version is not supported by which Gradle release.

First of all, visit the page Compatibility Matrix Gradle | Java enter image description here

In your situation you are using version gradle 6.7. So your version of java must be 15 or lower. Therefore, you can use a version of java 11, for example.

Solution 1 - change java version.

As a quick solution to the problem you can to change org.gradle.java.home in gradle.properties (or add this line):

# android/gradle.properties

org.gradle.java.home=C:\\Ruble\\jdk-11.0.18 

As you understand, you need to download the appropriate version of java before doing this. For example, here - Download Liberica JDK

The option is convenient because at this point you may already have java installed, but not the right version. This way we do not touch the global version of java (and do not change environment variables, etc.)

Another way could be to change the java in the Android Studio setup:

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

enter image description here

But in some cases this section may not exist.

Solution 2 - change gradle version.

According to the compatibility table above, you can change the version of gradle:

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

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

For example, for java 11 the version of gradle must be 5.0 or higher.


If you have java installed, you can find out its version with the command:

java -version

Also, you must consider the compatibility of the kotlin and gradle versions:

enter image description here


Hope this helps you save time and money on headache pills :)

like image 52
Ruble Avatar answered Nov 21 '25 13:11

Ruble


Hi I was facing the same problem and what worked for me was opening the Android folder inside the project. This way it configures few things missing when opening the generic Flutter project.

File > Open > select Android inside your project folder

enter image description here

Hope it helps.

like image 43
Diego Salvati Avatar answered Nov 21 '25 15:11

Diego Salvati



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!