Home>

Hi, I'm currently making an app that runs on Android with Unity, but I get the following error
Does anyone know the solution?

Purpose

I want to make an Android application with Unity

Status

When I try to start or build a project, "Gradle failed to fetch dependencies." Is displayed, and then the following message is displayed.

ERROR: JAVA_HOME is set to an invalid directory: C: \ Program Files \ Java \ jdk1.7.0_51

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

What I tried

-Installed the JDK and set JAVA_HOME to C: \ Program Files \ Java \ jdk1.8.0_271 in the system environment variable.
-Edit Unity->Preferences->External Tools->Set C: \ Program Files \ Java \ jdk1.8.0_271 in SDK
・ Unity Assets → External Dependency Manager → Android Resolver → Resolve
-Reinstall Unity
-Delete the project library and rebuild the project

Despite doing the above, the situation does not change. In short, it feels like Unity doesn't recognize the JAVA_HOME environment variable setting or hasn't changed from the previous setting.

environment

OS: Windows10 64bit
Unity: 2019.4.13f1

  • Answer # 1

    I think the system environment variable JAVA_HOME is incorrect.
    Isn't it C: \ Program Files \ Java \ jdk1.7.0_51?

    C: \ Program Files \ Java \ jdk1.8.0_271

    If you are in a Windows environment, check below.

    At the command prompt

    echo% JAVA_HOME%


    Also, check the JVM version with -v of gradle.
    (It is OK if the above environment variables and JVM match)

    gradle -v