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?
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

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.
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.)
Preferences → Build,Execution,Deployment → Build Tools → Gradle

But in some cases this section may not exist.
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:

Hope this helps you save time and money on headache pills :)
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

Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With