Unity failing to build apk
Hi. I have a game which I am trying to build as an apk. I have installed both java jdk and android sdk. However, every time I attempt the build it says "Failed to build apk. See console for details." In the console it gives this message:
CommandInvokationFailure: Failed to build apk. C:/Program Files/Java/jdk-9\bin\java.exe -Xmx2048M -Dcom.android.sdkmanager.toolsdir="C:/Program Files/Android/android-sdk\tools" -Dfile.encoding=UTF8 -jar "C:\Users\Owner\Desktop\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.(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.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) UnityEditor.HostView:OnGUI()
Does anyone know what this message means or what I need to do to make this work? Any help would be appreciated.
Answer by michelangeloevil · Oct 13, 2017 at 03:03 PM
im having the same problem. I installed the latest java jdk 9, the latest android studio version, linked it correctly and still getting almost the same error :(
found the answer here:
http://answers.unity3d.com/questions/1415655/android-apk-build-failed-error-how-do-i-fix-this.html
just downgrade to jdk 8. jdk 9 does not work because of a missing class.
I tried using jdk8 and the error persisted...