this generally happens after updating the android studio and/or updating java on your system , i have updated the android studio and java as well , studio to
Android Studio Ladybug | 2024.2.1 Patch 2 Build #AI-242.23339.11.2421.12550806, built on October 24, 2024 Runtime version: 21.0.3+-12282718-b509.11 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Toolkit: sun.awt.windows.WToolkit Windows 11.0
and java to jdk-23.
and got this error while building.
solution
change the jdk use by your flutter by executing
flutter config --jdk-dir 'path-to-your-jdk-of-choice'
the 'path to your choice is the path to the folder where jdk is located normally "C:\Program Files\Java\jdk-19" like this , in my case i needed to use gradle dist distributionUrl=https://services.gradle.org/distributions/gradle-7.6.3-all.zip
which is compatible with jdk 19, you can find the compatible vesrion and the matrix here