This problem occurred when I run my old Flutter
project that I coded 2 years ago. I think with Android project will also fix in the same way. I'm use MacOS
and Android Studio Bumblebee
.
First, need to move to the android
folder and check gradle version:
cd android
./gradlew --version

It show Gradle version 6.7.1
and you need attention to the JVM line, and my JDK version is 15.0.2. It is too new for this project. So you must to downgrading
from open jdk version to old version or upgrade
Gradle version in gradle/wrapper/gradle-wrapper.properties
to new version.
If you downgrade JDK version, you can download from this. In my case, I downgraded from Java SE 15 to Java SE 11.
After I open Android of Flutter project

Go to Preferences->Build, Execution, Deployment → Build Tools → Gradle →
and choose JDK version 11.

Go to Build -> Clean Project -> Rebuild Project.

Go to Terminal
run java --version
, if it still show JE version 15 then You must set JAVA_HOME before.
You only need to add the following to your .bash_profile
or .zshrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.15.jdk/Contents/Home
Save and go to android
folder and run again
./gradlew --version
It will show JDK version 11 correct.

Finally, run flutter run
.