'JDK directory is not set or invalid (unity)?
I am now creating a keystore for my game (in unity) but when I press the add key button, an error pops up
Java Development Kit (JDK) directory is not set or invalid. Please, fix it in Preferences -> External Tools UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:187)
I installed the JDK and checked the path of it in the terminal using the command /usr/libexec/java_home
, then it shows me that the path of the JDK is /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home
.
I copy and paste it in the JDK path in unity but the error still pops up. I actually checked the JavaVirtualMachines in my computer's library but there's nothing in it.
How can I solve this problem? Any help is greatly appreciated.
Solution 1:[1]
Actually I solve this problem by adding the modules (Android SDK & NDK Tools, OpenJDK) to my Unity Editor. Actually if you tick the Android build support module, it won't automatically help you to tick the two modules above.
Solution 2:[2]
I had the same problem, another solution doesn't work for me!!
I just uninstalled and then installed back using the unity HUB and it's worked.
Click on the three dots and uninstall
then click on add to install back the desired module. While installing don't forget to check android build support and its all subcategories.
Also, I think I had installed more than one version of unity, that could also be a problem.
Solution 3:[3]
- Check your Unity installation path in my case
C:\Program Files\Unity\Hub\Editor\2019.4.13f1\Editor\Data\PlaybackEngines\AndroidPlayer
this AndroidPlayer folder in NDK, SDK, and OpenJDK these folders are important for APK file generation.
These files are not properly installed then these files copy for another unity version.
Only one version you have then re-download it.
- Edit the environment variable like this path in your case path was different but make sour bin folder is important.
C:\Program Files\Unity\Hub\Editor\2019.4.13f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin
Solve the problem.
Solution 4:[4]
I solve the problem by changing the paths inside: edit->preferences->external tools To point to the correct version as I download a different version for the SDK, NDK and JDK when using the hub. This can be done by ticking the checkboxes.
Solution 5:[5]
This solved for me in Linux (don't know if the case happens in Windows)
chmod -R 777 ~/Unity
This command set all privileges for all files/directories/subdirectories for the user.
Getting the error of this topic, for curiosity I tried to run the "java" executable inside the directory
~/Unity/Hub/Editor/2021.3.1f1/Editor/Data/PlaybackEngines/AndroidPlayer/OpenJDK/bin/
And got: bash: ./java: Permission Denied
This explains why set the privileges.
Solution 6:[6]
As @Jelly Qwerty answered, installing android platform alone won't install jdk, sdk and ndk. What you got to do is:
- Open Unity Hub
- Go to "Installs"
- Click on the 3 dots on the upper right corner of your unity installation and select "Add Modules" Unity Hub Settings 1
- Expand "Android Build Support" and check "Android SDK & NDK Tools" and "OpenJDK". Unity Hub Settings 2
- Once the tools are installed you should be able to build your apk.
Cheers
Solution 7:[7]
I unchecked and checked the box for "JDK installed with untity" in Preferences>Externals Tools.
A window popped up and it installed some files and it fixed my issue
Solution 8:[8]
In Unity hub navigate to your unity versions, in the desire version click the doted menu and select add modules, if you already have android support, it has other options to install the android skd, ndk, and open ndk
Solution 9:[9]
There is no 3 dots and there is no installing JDK, Gradle, SDK, or NDK. I always get Gradle building errors when I install these components manually, although they are the compatible ones of my version. I want to download them automatically by unity, but the options you are talking about don't exist.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow