Sunday, July 29, 2018

Having problems with JDK / SDK Android Publishing with Unity Game Won't Build [Solution]

I was having some problems building an APK for android with unity 2018.1.6f1 Personal, and here is my solution:

Here was one console error:


UnityEditor.BuildPlayerWindow+BuildMethodException: 11 errors
  at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (BuildPlayerOptions options) [0x0021f] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:182
  at UnityEditor.BuildPlayerWindow.CallBuildMethods (Boolean askForBuildLocation, BuildOptions defaultBuildOptions) [0x00065] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:89
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

and another:
Build completed with a result of 'Failed'
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

I also got this error:

Unity Editor Error CS0234: Build doesn't exist in the namespace "UnityEditor"
Here is where I found part of the answer:

Specifically:

To Install the JDK Software and Set JAVA_HOME on a Windows System
  1. Install the JDK software.

    1. Go to http://java.sun.com/javase/downloads/index.jsp.
    2. Select the appropriate JDK software and click Download. The JDK software is installed on your computer, for example, at C:\Program Files\Java\jdk1.6.0_02. You can move the JDK software to another location if desired.
  2. Set JAVA_HOME:
    1. Right click My Computer and select Properties.
    2. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1.6.0_02.



    Here is another issue:

    Java 9 (JDK 9) support by Unity Android [ Currently NOT supported ]

    So you need to use JDK 8 & Make sure that your JAVA_HOME: points to C:\Program Files\Java\jdk8.(whatever version you have here)


    https://forum.unity.com/threads/java-9-jdk-9-support-by-unity-android.499354/
    Announcement:

    If you are using JDK 9 or JDK10 and trying to build for Android in Unity - you're most likely to have your build failed, with message like "Unable to list target platforms" - "Error:Invalid command android".

    We are working together with Google on fixing this issue - it requires fixes on Unity side, but also Android SDK tools need to be updated to be compatible with latest Java.

    In the meanwhile, we recommend using Java 8 (JDK 8) 64-bit.

    We apologize for the inconvenience caused!
    Your Unity Mobile team

    EDIT: looks like if you have different JDKs installed, despite selecting JDK8 in the Unity Editor preferences, Android SDK continues to use later JDKs. The only known solution at the moment is to UNINSTALL JDK9 and JDK10, and have only JDK8 (64-bit) installed.

    I hope this helps. 
Recap.

In Order to fix your issue:  

#1 UNINSTALL ALL JAVA 9 AND 10 FROM YOUR COMPUTER.

#2 UNITY>EDIT>PREFERENCES>EXTERNAL TOOLS> SDK (should point to your SDK Folder) && JDK (should point to your JDK1.8.0_181 file) 

#3 make sure your JAVA_HOME is set to your JDK1.8.0_181 file 

#4 UNITY>FILE>BUILD SETTINGS> Make sure this is set to Android. 

#5 Build from build settings to your destination, same as project files(is this required?)

Congrats now you have an APK!

Good work! 

Keep on kraken!

No comments:

Post a Comment