How to set JAVA_HOME using OpenJDK?

I installed Unity 2019.1.5f1 , and I am using Firebase. When I used Android Resolver there is this problem that says I need to set JAVA_HOME:

Gradle failed to fetch dependencies.

ERROR: JAVA_HOME is not set and no ‘java’ command could be found in your PATH.

As far as I know Unity is using OpenJDK which is fine by me, but how to I set the JAVA_HOME using the OpenJDK? I don’t even know where it is located. How do I set the JAVA_HOME variable using OpenJDK?

1 Like

@HugoStudica

Link should look like this (I’m using Windows):

C:\Program Files\2019.1.7f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\OpenJDK\Windows\

To edit JAVA_HOME:

  • right click on My Computer and select Properties
  • go to Advanced Computer Settings
  • click on Environment Variables
  • Edit JAVA_HOME with the path or add new variables if not listed
  • reboot computer

I set the variable as in the next link. Worked for me.
https://confluence.atlassian.com/doc/setting-the-java_home-variable-in-windows-8895.html

Thanks for this work around I read your comments and applied and all is working good can’t believe the software is so unstable

Thank you for your ideas. They are really helpful. I couldn’t imagine that such troubles might occur with the software.

Resolved!

After importing the firebase SDK into Unity 2021.3.3f1 I got an error related to JAVA_HOME not pointing to the Java used by Unity. To solve it I had to

  • change Windows 10 → Settings → System → Edit System variables
  • Change the value of “JAVA_HOME” to my Unity Java version:
    “F:\Programs\Unity\2021.3.3f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK”
  • Reboot my Computer (for the JAVA_HOME change to take effect)
  • In Unity: Click on Assets → External Dependency Manager → Android → Resolve

Not sure if the last step was necessary. I tried a lot of things (including “regenerating project files” - from Unitys settings)