This error typically occurs when the version of Gradle used in your Flutter project does not match the version of Java installed on your machine.
Error message:
Gradle version:
Java version:
For more detailed information about Java and Gradle version compatibility, please refer to the compatibility matrix: compability matrix
So, this error occurs because the version used by your Flutter project does not match the version on your local machine.
This can happen if you installed the SDK using Android Studio.
So, you can fix this by changing the Java version path used by Flutter with the following command
LINUX:
flutter config --jdk-dir /usr/lib/jvm/java-17-openjdk-amd64
Note: Adjust the path to match the version you want to use.
And now your Java Runtime version is set to version 11