-2

JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jdk1.8.0_281\bin

Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

How to solve this problem??

Ryan M
  • 18,333
  • 31
  • 67
  • 74
  • 3
    Does this answer your question? [JAVA\_HOME is set to an invalid directory:](https://stackoverflow.com/questions/45182717/java-home-is-set-to-an-invalid-directory) – Benyamin Sep 03 '21 at 08:47

2 Answers2

0

You need to explicity download and define the jdk version to be used in the code for running the flutter app.

I also faced the similar issue and below solutions works for me:

Install jdk 11 and add path to gradle.properties file

org.gradle.java.home=C:\\Program Files\\Java\\jdk-11.0.11

enter image description here

Nitish
  • 3,075
  • 3
  • 13
  • 28
  • Its always a good idea to explain WHY your answer works and not just give an answer for someone to blindly follow https://stackoverflow.com/help/how-to-answer – DevWithZachary Sep 03 '21 at 08:41
  • 1
    Thanks , I will edit the answer with explanation and try to follow this in future – Nitish Sep 03 '21 at 08:43
0

This happens because your JAVA_HOME is not set correctly. -> It is essential to set the java path when working on android. so, Please find these steps below.

  1. Go to system properties -> Advance -> Environment Variables ( or just type ENV in search )

  2. Click new on system variables enter image description here

  3. Add variable name as "JAVA_HOME" and Variable value will be the directory of java sdk // (do go to bin folder just java folder)

enter image description here

  1. click on path in system variables

enter image description here

  1. Then add new variable as "%JAVA_HOME%\bin

enter image description here

Now I hope your issue will be fixed.

Alan Bosco
  • 737
  • 5
  • 20