Kevin Griffiths
Kevin Griffiths

Reputation: 161

Failed to build APK. See console for details

I've built an App and got it on the App store, and now I'm trying to build to a Samsung A3 2016.

I've dowloaded the latest Android studio, and the JDK, the JDK is idk-9.jdk

When Googling this problem people are saying try JDK 8, but when I remove JDK 9 then download and install JDK 8 it's still showing as JDK 9.

When I look in the user/Library/ there is NO Java Dir!

I'm using macOS Sierra, Unity 2017 and Android 7.0

Any help would be greatly appreciated.

The error I'm getting is this ..

CommandInvokationFailure: Failed to build apk.
/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/bin/java -Xmx2048M -Dcom.android.sdkmanager.toolsdir="/Users/kevingriffiths/Android/sdk/tools" -Dfile.encoding=UTF8 -jar "/Applications/Unity/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.BuildPlayerWindow:BuildPlayerAndRun()

Upvotes: 0

Views: 1540

Answers (1)

Zoe - Save the data dump
Zoe - Save the data dump

Reputation: 28278

The sun.* packages shouldn't be used. Refer this:

The sun.* packages are not part of the supported, public interface. A Java program that directly calls into sun.* packages is not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform. Each company that implements the Java platform will do so in their own private way. The classes in sun.* are present in the JDK to support Oracle's implementation of the Java platform: the sun.* classes are what make the Java platform classes work "under the covers" for Oracle's JDK. These classes will not in general be present on another vendor's Java platform. If your Java program asks for a class "sun.package.Foo" by name, it may fail with ClassNotFoundError, and you will have lost a major advantage of developing in Java.

You have to use a different Base 64 package. If you're using Java 8+, java.util.Base64 should do the trick. Otherwise you have to use a different Base64 API, for an instance this one by Apache in the commons library

Upvotes: 1

Related Questions