How do I solve CommandInvokeFailure?

Hello. The problems have started yesterday, when I couldn’t build my android game because unity couldn’t “list target platforms”. I looked up the solution in the internet and it really helped me. But then unity started saying: “CommandInvokationFailure: Failed to build apk.” I looked for the solution again (2) but it didn’t work.

Here is the whole report:

CommandInvokationFailure: Failed to
build apk.

C:/Program
Files/Java/jdk-9\bin\java.exe
-Xmx2048M -Dcom.android.sdkmanager.toolsdir=“C:/Users/Turar/AppData/Local/Android/sdk ools”
-Dfile.encoding=UTF8 -jar “C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\sdktools.jar”

stderr[ Exception in thread “main”
java.lang.reflect.InvocationTargetException
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
Method) at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at
java.base/java.lang.reflect.Method.invoke(Method.java:564)
at SDKMain.main(SDKMain.java:129)
Caused by:
java.lang.NoClassDefFoundError:
sun/misc/BASE64Encoder at
com.android.sdklib.internal.build.SignedJarBuilder.(SignedJarBuilder.java:177)
at
com.android.sdklib.build.ApkBuilder.init(ApkBuilder.java:446)
at
com.android.sdklib.build.ApkBuilder.(ApkBuilder.java:422)
at
com.android.sdklib.build.ApkBuilder.(ApkBuilder.java:362)
at
UnityApkBuilder.(UnityApkBuilder.java:214)
at
UnityApkBuilder.main(UnityApkBuilder.java:34)
… 5 more Caused by:
java.lang.ClassNotFoundException:
sun.misc.BASE64Encoder at
java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
at
java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:563)
at
java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
… 11 more ] stdout[

] exit code: 1
UnityEditor.Android.Command.Run
(System.Diagnostics.ProcessStartInfo
psi,
UnityEditor.Android.WaitingForProcessToExit
waitingForProcessToExit, System.String
errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommandInternal
(System.String javaExe, System.String
sdkToolsDir, System.String
sdkToolCommand, Int32 memoryMB,
System.String workingdir,
UnityEditor.Android.WaitingForProcessToExit
waitingForProcessToExit, System.String
errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommandSafe
(System.String javaExe, System.String
sdkToolsDir, System.String
sdkToolCommand, Int32 memoryMB,
System.String workingdir,
UnityEditor.Android.WaitingForProc
essToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.HostView:OnGUI()

What should I do?

P.S: I also thought that the problem is with my keystore but it’s not

P.P.S: I have the latest SDK version and unity5.6.0f3

Thanks in advance!

Ok, whoever reads it, I got the solution.

After hours of searching the internet I read that sometimes Unity doesn’t work properly with the last versions of JDK. So I downgraded my JDK from 9 to 8 and installed 86bit version. Now it works fine.

My concern is that there is an article that talks about don’t use the sun package in a java project
so why is unity doing that? FAQ - Sun Packages