How to fix ERROR: JAVA_HOME is set to an invalid directory (Flutter android licenses)
Solution 1
First of all you need to install "Android SDK Command Line Tool" in andriod studio. Settings > System Settings > Android SDK > SDK Tool --> Android SDK Command Line Tool (as shown in the following screenshot)
Then watch this video -> https://www.youtube.com/watch?v=104dNWmM6Rs&ab_channel=CodeJava
Solution 2
I ran same issue like this and spend couple of hour on it and finally solved it. I am sharing my solution as someone might get beneficial.
First Issue : When i ran flutter doctor --android-licenses
, i got below error.
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
Second Issue : Then i thought it would be lack of jdk so i install jdk 8 , setup JAVA_HOME environment variable and ran flutter doctor --android-licenses
, i got another error shown below.
ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk-jdk1.8.0_29
Please set the JAVA_HOME variable in your environment to match the location of your Java installation.
Solution : I installed Android SDK command line tool as shown in screenshot above in Android Studio and removed JAVA_HOME environment variable. Then i restart my laptop and it works. This issue has been discussed on flutter official github so here is the link https://github.com/flutter/flutter/issues/84325. I thank to TahaTesser and Pasindu Dilanka.
Conclusion :
There is no need to setup external jdk, as
default JDK that comes with Android Studio itself, which is java 11.
- TahaTesser
Shiva Nach
Updated on November 21, 2022Comments
-
Shiva Nach over 1 year
This whole issue occurred when i ran
flutter doctor
in cmd.Flutter doctor showed issue as:Android toolchain - develop for Android devices (Android SDK Version 30.0.3) Android license status unknown. Run
flutter doctor --android-licenses
to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.So, I ran
flutter doctor --android-licenses
then it showed output as:ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk-16.0.1\bin
Please set the JAVA_HOME variable in your environment to match the location of your Java installation.
I have tried many methods like: change the directory to
C:\Program Files\Java\jdk-16.0.1
(no bin) but then when i runflutter doctor --android-licenses
it showsException in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156) at com.android.repository.api.SchemaModule.(SchemaModule.java:75) at com.android.sdklib.repository.AndroidSdkHandler.(AndroidSdkHandler.java:81) at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73) at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48) Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519) ... 5 more
Please help me solve this issue, Thank You!
-
Swaminathan V almost 3 yearsTry to reinstall JAVA.
-
Stephen C almost 3 yearsReinstalling Java is not a solution. Fixing JAVA_HOME is the solution.
-
-
Mr R almost 3 yearsHi @PasinduDilanka - welcome to Stack Overflow. Please add some words describing about what the video is about.
-
George over 2 yearsWelcome to SO. Though we thank you for your answer, it would be better if it provided additional value on top of the other answers. In this case, your answer does not provide additional value, since Prakash Karkee already posted that solution. If a previous answer was helpful to you, you should vote it up once you have enough reputation.