- Home /
Android APK build failed error. How do I fix this?
So I'm trying to upload this simple game I've made on Unity to Android. Unfortunately, whenever I attempt to build it I get this error in my console:
Error building Player: CommandInvokationFailure: Failed to build apk. See the Console for details. C:/Program Files/Java/jdk-9\bin\java.exe -Xmx2048M -Dcom.android.sdkmanager.toolsdir="C:/Users/Owner/Desktop/sdk\tools" -Dfile.encoding=UTF8 -jar "C:/Users/Owner/Downloads/Unity 4.6/Editor/Data/BuildTargetTools/AndroidPlayer\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:201) at UnityApkBuilder.main(UnityApkBuilder.java:28) ... 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[
]
I am extremely new to Unity, app-developing, and programming in general, so please, if you could, try and make your answer as simple as possible, as most of the answers I've found in other forums either don't work or I don't understand. Thanks!
Answer by CharlesWard · Oct 04, 2017 at 08:23 PM
It seems that Java 9 removed the sun/misc/BASE64Encoder class.
A workaround is to downgrade to Java 8.
Where might I find JD$$anonymous$$ 8? The downloads page only had version 9.
Hey, It works! Thanks a lot, you just saved me a ton of frustration!
Yes, just download the 8 and change the path in your project settings... All those problems omfg...
I cannot change my JD$$anonymous$$ path in External Tools, please help, Im a newbie in Unity
Download and Install JD$$anonymous$$ 8 : http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
In Unity : Edit → Preferences → External Tools , then pull the bottom of this window, and you will see the Android Path Browse Button (yes it is well hidden, for nothing...)
Click Browse and find where you installed the JD$$anonymous$$ ( C/Programs/Java/Jdk1.8 ) One bug fixed now, have fun with the next one ^^
Answer by SirDef11 · Oct 09, 2017 at 11:51 AM
Download and Install JDK 8 : http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
In Unity : Edit → Preferences → External Tools , then pull the bottom of this window, and you will see the Android Path Browse Button (yes it is well hidden, for nothing...)
Click Browse and find where you installed the JDK ( C/Programs/Java/Jdk1.8 ) One bug fixed now, have fun with the next one ^^
I logged in for the first time ever on these forums and this is my first comment, just to say thank you. I've been working for 6 f'ing hours on getting my first game to work on my phone and after step by step of going on the forums, doing this, doing that, doing this, doing that, you'rs was the final answer. I did it, it worked. Game worked. Everything worked. $$anonymous$$y life worked. Suddenly I could see everything clearly and my life just came back together with that glorious few seconds. This message...your message, was the best thing I've came across all month. Thanks buddy!
You're welcome. I had the same feeling the first time lol ^^ Now if you decide to continue, have fun with the next bugs. (currently, i'm at a problem with no solution... after 200 or 300 hours of work, just imagine the desilusion...). Have fun anyway ^^
Answer by cpsstudios · May 19, 2018 at 09:26 PM
I know this is late... but I concur!!! This worked for me!!! Kudoz to the one that figured this out. Thanks.
Your answer

Follow this Question
Related Questions
lightmap comes out blurry on android device 0 Answers
GPU warning Post Processing Stack android 0 Answers
Frame Rate jumps between 20 to 8000 ( in thousands) continuos and periodically. 0 Answers
UnityEditor.BuildPlayerWindow+BuildMethodException - Anyone guide to solve this ERROR please??? 0 Answers