0
\$\begingroup\$

i am getting this error whenever i am trying to build a project. i looked at so many solutions but this one just doesn't go away.

This is the error:

CommandInvokationFailure: Failed to build apk.
C:\Program Files\Java\jdk-9\bin\java.exe -Xmx2048M -Dcom.android.sdkmanager.toolsdir="C:/Users/Mohit/AppData/Local/Android/sdk\tools" -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:130)
Caused by: java.lang.NoClassDefFoundError: sun/misc/BASE64Encoder
    at com.android.sdklib.internal.build.SignedJarBuilder.<init>(SignedJarBuilder.java:177)
    at com.android.sdklib.build.ApkBuilder.init(ApkBuilder.java:446)
    at com.android.sdklib.build.ApkBuilder.<init>(ApkBuilder.java:422)
    at com.android.sdklib.build.ApkBuilder.<init>(ApkBuilder.java:362)
    at UnityApkBuilder.<init>(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.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.HostView:OnGUI()

what i have tried so far:

1) downgrading android sdk 2) moving zipalign file from build-tools to tools folder 3) setting up keystore

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Make sure you are using jdk 8 and unity is pointing to the right location

\$\endgroup\$
4
  • \$\begingroup\$ i am using jdk 9. is that a problem? \$\endgroup\$ Commented Sep 29, 2017 at 8:15
  • \$\begingroup\$ Might be, the sun.misc.Base64Encoder is providing warnings in JDK8 that it might be removed in future releases \$\endgroup\$
    – Niels
    Commented Sep 29, 2017 at 8:19
  • \$\begingroup\$ I got this same error last night while setting up a new computer to build from Unity to Android and I also was using jdk 9. So this answer could be on to something. \$\endgroup\$ Commented Sep 29, 2017 at 18:04
  • \$\begingroup\$ for some weird reason it started working when i downgraded to JDK 8. \$\endgroup\$ Commented Oct 3, 2017 at 7:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .