I am currently developing a Flutter application on my Mac and am trying to test my app on an Android emulator. To facilitate this, I have installed Android Studio along with the Android SDK. Running flutter doctor --verbose
shows that everything has been set up correctly.(no warings or errors)
However, I am encountering an issue related to Java versions. When I attempt to start my app for Android, I receive an error stating that my Gradle version (Gradle-6.9.3, which I prefer not to change) is incompatible with my JDK. According to the error message, my system needs to use Java 15 to achieve compatibility.
When I run java --version
, the output indicates that I am indeed using Java 15. Furthermore, I've set my $JAVA_HOME
environment variable to the output of /usr/libexec/java_home -v 15
, so it should be referencing the correct Java version.
However, the issue persists. When I execute flutter doctor --verbose
, it returns Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
. This suggests that Flutter is using Java 17 instead of Java 15, which is referenced by $JAVA_HOME
.
My hypothesis is that either Flutter or Android Studio might be using their own bundled JDK, which seems to override my system settings. I am looking for a way to change this behavior so that Flutter uses the JDK version specified in $JAVA_HOME
.
In an attempt to solve this issue, I have installed Java 15 and configured the $JAVA_HOME
environment variable accordingly. Additionally, I modified the Flutter command so that it sets the correct $JAVA_HOME
value right before executing Flutter.
Despite these adjustments, it seems that Flutter is still ignoring the $JAVA_HOME
variable and opting to use the bundled Java version instead. This is problematic because I need to use Java 15 for compatibility with other tools and libraries in my project.
I considered the possibility of completely removing Java 17 from my system as a potential solution. However, when I ran sudo /usr/bin/find / -name "*.jdk"
to locate any installed JDKs, I was unable to find JDK 17. Also, running /usr/libexec/java_home -V
does not show JDK 17.
I expected Flutter to use the JDK version as specified in the $JAVA_HOME
environment variable. Instead, it appears to be using its own bundled version, irrespective of my system settings.
Does anyone have an idea about how to rectify this? Any advice or guidance would be greatly appreciated. Thank you!