I'm building a little android game with Unity 2018.2.2 (last version on 08/08/2018). I worked on the game for some weeks but now, without appareantly reason Unity fail when it try to locate my JDK. When I assign the folder (edit->preferences->external tools) it fails and show me the next problem:

[If you can't see the image: "Failed to detect Java version. Android development requires JDK 8 (1.8). Having Java Runatime Environment (JRE) installed is not sufficient."]
The first I think was, may it fails because an JDK's update, so I check if the variable path is ok, and it is. Then, I uninstall the jdk and I install again (jdk1.8.0_181). It install normally with 2 folders (jdk1.8.0_181 and jre1.8.0_181) and I update the variable path to "JAVA_HOME C:\Program Files\Java\jdk1.8.0_181\bin" (in my case). But when I try to select this folder in Unity, Unity show me the error of the image. I'm really confuse. Four days ago it works properly. What could be failing?? This is the log when I try to build the APK and I select the folder of the JDK:
UnityException: Build failure! Unable to locate Java Development Kit (JDK). UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck(String[], String, String, BuildTargetGroup, BuildTarget, BuildOptions, Boolean) UnityEditor.DefaultBuildMethods:BuildPlayer(BuildPlayerOptions) (at C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:170) UnityEditor.BuildPlayerWindow:CallBuildMethods(Boolean, BuildOptions) (at C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:94) UnityEditor.BuildPlayerWindow:GUIBuildButtons(IBuildWindowExtension, Boolean, Boolean, Boolean, BuildPlatform) (at C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindow.cs:891) UnityEditor.BuildPlayerWindow:ShowBuildTargetSettings() (at C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindow.cs:816) UnityEditor.BuildPlayerWindow:OnGUI() (at C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindow.cs:414) System.Reflection.MonoMethod:InternalInvoke(MonoMethod, Object, Object[], Exception&) System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) System.Reflection.MethodBase:Invoke(Object, Object[]) UnityEditor.HostView:Invoke(String, Object) (at C:\buildslave\unity\build\Editor\Mono\HostView.cs:295) UnityEditor.HostView:Invoke(String) (at C:\buildslave\unity\build\Editor\Mono\HostView.cs:288) UnityEditor.HostView:OldOnGUI() (at C:\buildslave\unity\build\Editor\Mono\HostView.cs:104) UnityEngine.Experimental.UIElements.IMGUIContainer:DoOnGUI(Event, Boolean) (at C:\buildslave\unity\build\Modules\UIElements\IMGUIContainer.cs:215) UnityEngine.Experimental.UIElements.IMGUIContainer:HandleIMGUIEvent(Event) (at C:\buildslave\unity\build\Modules\UIElements\IMGUIContainer.cs:380) UnityEngine.Experimental.UIElements.IMGUIContainer:HandleEvent(EventBase) (at C:\buildslave\unity\build\Modules\UIElements\IMGUIContainer.cs:359) UnityEngine.Experimental.UIElements.EventDispatcher:DispatchEvent(EventBase, IPanel) (at C:\buildslave\unity\build\Modules\UIElements\EventDispatcher.cs:260) UnityEngine.Experimental.UIElements.UIElementsUtility:DoDispatch(BaseVisualElementPanel) (at C:\buildslave\unity\build\Modules\UIElements\UIElementsUtility.cs:243) UnityEngine.Experimental.UIElements.UIElementsUtility:ProcessEvent(Int32, IntPtr) (at C:\buildslave\unity\build\Modules\UIElements\UIElementsUtility.cs:74) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:\buildslave\unity\build\Modules\IMGUI\GUIUtility.cs:171) (Filename: Line: -1)
Thanks in advance.
EDIT: Finally I solve the problem.Look at my answer if want more info.
I had the same problem. The following fix worked for me.
Go to Edit > Preferences > External Tools
Delete the JDK path (maybe also Android SDK path?)
Launch an Android Build
Unity will show the message "Unity has detected Java Development Kit (JDK) at [jdk path]. Do you want to use this JDK Directory?"
Press Yes
It is also worth noting, that there is currently an incompatibility between Unity, Android and the latest versions of JDK. But it seems that you already have the currently correct JDK version: 1.8.0_181
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With