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 ools” -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!

It seems that Java 9 removed the sun/misc/BASE64Encoder class.

A workaround is to downgrade to Java 8.

  1. Download and Install JDK 8 : http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  2. 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…)
  3. Click Browse and find where you installed the JDK ( C/Programs/Java/Jdk1.8 )
    One bug fixed now, have fun with the next one ^^

Same problem…

Watch this video: - YouTube

I know this is late… but I concur!!! This worked for me!!! Kudoz to the one that figured this out. Thanks.