Failed to update Android SDK package list error when using SDK installed with unity

Failed to update Android SDK package list error when using SDK installed with unity.

CommandInvokationFailure: Failed to update Android SDK package list.
F:/Programs/Unity/2019.2.0f1/Editor/Data/PlaybackEngines/AndroidPlayer\SDK\tools\bin\sdkmanager.bat --list

stderr[
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
    at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
    at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 5 more
]
stdout[

]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <8277255796414cc8b8865316c1676de5>:0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <8277255796414cc8b8865316c1676de5>:0)
UnityEditor.Android.SDKManager.UpdatePackagesList () (at <8277255796414cc8b8865316c1676de5>:0)
UnityEditor.Android.SDKManager.ListAvailable (UnityEditor.Android.SDKManager+Component type) (at <8277255796414cc8b8865316c1676de5>:0)
UnityEditor.Android.PlayerSettingsEditorExtension.<StartGettingReleasedAPILevels>m__0 () (at <8277255796414cc8b8865316c1676de5>:0)
System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) (at <a8ed250850854b439cedc18931a314fe>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <a8ed250850854b439cedc18931a314fe>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <a8ed250850854b439cedc18931a314fe>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) (at <a8ed250850854b439cedc18931a314fe>:0)
System.Threading.ThreadHelper.ThreadStart () (at <a8ed250850854b439cedc18931a314fe>:0)
UnityEngine.UnhandledExceptionHandler:<RegisterUECatcher>m__0(Object, UnhandledExceptionEventArgs)

Unity 2019.2.0f1 and Hub 2.0.4.

Edit: Nevermind, fixed by removing my other java install from java home and path.

4 Likes

Good day.
I faced the same problem.
Did you manage to find a solution?

1 Like

Yeah, as I said in the OP, I removed java_home and the java path from my environment variables, (just deleted them, I did not add a new one).

2 Likes

You may need to install Java8. The Android SDK refers to the system’s JDK …
Perhaps the currently installed JDK is 11 or 12, so it is quick to remove it.
However, to install Oracle Java8, you need to register an account, and using Open JDK may be easier.

https://azul.com/downloads/zulu/

I really want to use the JDK bundled with Unity. Is there a good way?

Yes.

1 Like

Hi,
What does it mean to remove java_home and the java path from environment variables?

4 Likes

Same. Some articles say remove environment variables… some say add them… working with unity and mobile is just always a nightmare.

32 Likes

On Windows, java uses an environment variable, one named JAVA_HOME and it also might use the Path variable to find the java binaries.

https://docs.oracle.com/en/database/oracle/r-enterprise/1.5.1/oread/creating-and-modifying-environment-variables-on-windows.html#GUID-DD6F9982-60D5-48F6-8270-A27EC53807D0

New Unity comes bundled with Java so it shouldn’t need any external java “stuff”.
Removing them should fix any java issues, as long as you choose to install and use the bundled java.

However there is another bug on unity that leaves some path bars inverted and apparently this bugs the java usage.

Java 9 (JDK 9) support by Unity Android page-3#post-5724547

So I now just use a script to fix this stuff automatically…

string newJDKPath = EditorApplication.applicationPath.Replace("Unity.exe", "Data/PlaybackEngines/AndroidPlayer/OpenJDK");

        if (Environment.GetEnvironmentVariable("JAVA_HOME") != newJDKPath)
        {
            Environment.SetEnvironmentVariable("JAVA_HOME", newJDKPath);
        }

Put in on a static constructor on a class marked with [InitializeOnLoad] on the Editor folder of your project.

12 Likes

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

1 Like

Hey everybody, i have the same error on my windows10, and installed android studio latest version, I set android studio SDK path to unity android sdk path, and it is solved.

1 Like

Hi, I had the same problem and solved it as follows: 1. I uninstalled my previous version of Java. 2. Installed Java 8
(Java SE Development Kit 8u251). 3. Copied the path to my environment settings in Settings/Environment settings. Moved it up in the hierarchy 4. Also added JAVA_HOME path to the environment settings. 5, IMPORTANT Went to Unity: Edit/Preferences/External Tools.
6. Here I unticked the following boxes under ANDROID: (a) JDK installed with Unity (Recommended) and browsed to where Java is stored (C:\Program Files\Java\jdk1.8.0_251) (b) Did the same with SDK. 7. MAGIC!

I had same issue on Mac after previously making build without an issue. I uninstalled current Unity version ( 2019.3.4 ) through Unity Hub and installed new version ( 2019.3.14 ). If you have same issue, try to reinstall Unity version.

1 Like

We are using Unity 2019.3.12f1 and I’m getting this same issue on a Mac. We can’t update our project yet at the moment to a newer version of Unity. Does Unity have an official workaround for this? Is it actually fixed in a newer version of Unity?
Thanks.

Hey, I had the same issue on Ubuntu18.04. Yesterday I was able to build the Android apk but today I was not able anymore.
I fixed it exporting the JAVA_HOME environment variable (pointing to Unity Java SDK installation) and appending the Java executable to the PATH environment variable:

export JAVA_HOME=/home/leofaber/Softwares/unity/editors/2019.3.14f1/Editor/Data/PlaybackEngines/AndroidPlayer/OpenJDK
export PATH=$JAVA_HOME/bin:$PATH
3 Likes

fixed by unchecking all checboxes bellow and check them again
P.S : you find it in unity under Edit → Preferences → External Tools

112 Likes

I had this problem too, seemingly out of nowhere. My Android game compiled one night and the next it didn’t. I did enable the keystore for it, maybe that caused it?

But I uninstalled Java (I had v13 I believe) and re-installed JDK v8. I also added the JAVA_HOME environment variable since it wasn’t there (following Yerbol05’s link above) after installation. I then went into Unity → Edit → Preferences → External Tools, unchecked the Unity Open JDK, and specified the Java installation directory (C:\Program Files\Java\jdk1.8.0_251).

My game then compiled. I was thinking it was due to some Android SDK issue, cause of the error message, but it seems to have been Java (for whatever reason).

2 Likes

can you upload video? because i have the same problem but I don’t understand

Hi. i had same problem and i solved.
i remove my JAVA_HOME variable but it doesn’t change any thing.
i have unity 2019.4(lts) and java 8 and updated SDK and i added java_home in my variables. i download a another version of JDK and SDK and put them in unity! and i try to build, and my error fixed. now i back my jdk and sdk and try to build again and its work!

1 Like

This is the one!! Simple as can be…

Thank you, It works for me on MacOS 10.15.5 (19F101) Unity 2019.3.14f1