Just a reminder that Flutter has the --jdk-dir
configuration.
If you encounter a Java compatibility error and are certain that you've changed your Java version, make sure to also set the --jdk-dir
configuration in Flutter. This happened to me when I installed Android Studio, which comes bundled with Java 21.
I received a Java compatibility error despite being sure I had set Java to version 17. I verified it by running the command java --version
, which showed that I was using JRE and JDK version 17.
It turns out (I'm not sure why) that Flutter was using Java 21, which comes with the Android SDK, even though I had set my $JAVA_HOME
to my local Java installation. It's really strange, though.
You can run flutter config --jdk-dir=$JAVA_HOME
to make sure that flutter use java from your JAVA_HOME