flutter doctor --android-licenses gives a java error
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
When working with Flutter, a popular framework for crafting natively compiled applications from a single codebase, it is essential to ensure that development tools and environments are properly configured. One such utility, flutter doctor, is instrumental in identifying and diagnosing common issues with the configuration of the development environment. This command checks for installed tooling and dependencies and provides guidance on setting up required components. However, a common issue faced by developers, particularly when interacting with Android tooling, is that running flutter doctor --android-licenses might yield a Java-related error message.
Understanding the flutter doctor --android-licenses Command
The flutter doctor --android-licenses command verifies that all Android licenses are agreed upon. This command is necessary because Android SDK components have separate licensing agreements that must be accepted before use. This step is crucial to ensure legal compliance and proper functioning of the SDK components.
Common Java Error
The typical error message displayed is something akin to:
or it may complain about other Java classes or components. This error primarily indicates that there's an issue with the Java version installed on the system, or the Java environment paths are not correctly configured.
Root Cause of the Error
The root cause of this error can usually be traced back to compatibility issues between the Java Development Kit (JDK) version installed on the developer’s machine and what Android's SDK command-line tools expect. Android's command line tools, used by the flutter doctor --android-licenses command, require JDK 8 (1.8). However, issues might arise when a higher version of the JDK is installed – particularly versions higher than JDK 9, due to changes in the Java platform.
How to Fix the Error
To resolve this issue, follow these steps:
- Verify Installed JDK Version: First, check which JDK version is installed on your system. This can be done by running:
If the version is above 8, consider installing JDK 8 alongside the existing version.
- Install JDK 8: Download and install JDK 8 from the Oracle website or use a package manager if on Linux.
- Set JAVA_HOME Environment Variable: Set the
JAVA_HOMEenvironment variable to point to the JDK 8 installation directory. Additionally, add the JDK 8bindirectory to your PATH. How you set these environment variables depends on your operating system. - Re-run flutter doctor --android-licenses: After these changes, run:
Then, agree to any licenses that have not yet been accepted.
- Restart your IDE or Terminal: This ensures all newly made changes are picked up.
Additional Tips
- If you use multiple Java versions, consider using a version manager such as SDKMAN! for easier switching between versions.
- Always ensure that your environment variables like
PATHandJAVA_HOMEare correctly set up after installing new software that depends on these environment variables.
Summary Table of Key Actions
| Action | Purpose | Commands/Steps |
| Verify Java Version | Check current JDK version | java -version |
| Install JDK 8 | Ensure compatibility with Android SDK tools | Download from Oracle or use package manager |
| Set JAVA_HOME and PATH | Point system to use JDK 8 for Flutter | Set environment variables to JDK 8 directory |
| Run flutter doctor --android-licenses | Accept SDK licenses | flutter doctor --android-licenses |
| Restart IDE or Terminal | Apply changes | Close and reopen your development tools |
By accurately configuring the development environment with the correct JDK version and properly setting environment variables, developers can overcome the java error encountered during the execution of flutter doctor --android-licenses and continue building amazing Flutter applications for Android and other platforms.

