
Many Flutter developers run into mysterious Gradle or Kotlin-related build errors — especially when switching between projects or Flutter versions. One sneaky reason?
Flutter might not be using the Java version from
JAVA_HOME
, but instead the one bundled with Android Studio.
In this guide, you’ll learn how to:
- ✅ Check your Java version
- ✅ Check what Java Flutter is using
- ✅ Configure Flutter to use the correct JDK
- ✅ Reset to Android Studio’s JDK if needed
🔍 1. Check Your Java Version
java --version
Expected output (for example):
openjdk 17.0.12 2024-07-16
OpenJDK Runtime Environment Homebrew (build 17.0.12+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.12+0, mixed mode, sharing)
Then verify your JAVA_HOME:
echo $JAVA_HOME
Example:
/opt/homebrew/Cellar/openjdk@17/17.0.12/libexec/openjdk.jdk/Contents/Home
🔍 2. Check What Java Flutter Uses (Especially with FVM)
Even if your JAVA_HOME is set correctly, Flutter might still be using Android Studio’s built-in Java.
To find out:
fvm flutter doctor --verbose | grep Java
You might see something like:
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 21.0.4+...)
⚠️ This means Flutter is not using the Java you installed — it’s using Android Studio’s bundled JDK (Java 21 in this case).
🛠️ 3. Tell Flutter to Use Your Installed Java (e.g., Java 17)
To fix this, run:
fvm flutter config --jdk-dir $JAVA_HOME
This sets the JDK path explicitly for Flutter builds.
Then verify it:
fvm flutter doctor --verbose | grep Java
You should now see your system Java path from /opt/homebrew/….
🔄 4. Revert to Android Studio’s Built-in Java (Optional)
If you want to switch back to using the JDK bundled with Android Studio, just run:
fvm flutter config --clear
Now Flutter will once again use the JDK from:
/Applications/Android Studio.app/Contents/jbr/Contents/Home
⚙️ Bonus: Set JAVA_HOME in .zshrc or .bash_profile
Add the following to your shell config:
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
export PATH="$JAVA_HOME/bin:$PATH"
Then apply it:
source ~/.zshrc # or ~/.bash_profile
By being deliberate about which Java Flutter uses, you’ll avoid version mismatches and mysterious build errors — especially when working across different Flutter versions or Android Gradle Plugin setups.
Working with multiple Java versions can be tricky, especially when Flutter projects silently default to the Android Studio JDK. Knowing how to inspect and configure which JDK Flutter uses can save hours of debugging time.
Whether you’re building legacy projects or working with the latest Flutter version, keeping your environment in check ensures smooth builds and faster iteration. If you found this guide helpful, consider bookmarking it or sharing it with your team!