简体   繁体   English

Unity无法构建apk Android

[英]Unity Failed to Build apk Android

i followed the unity "tanks!" 我遵循统一的“坦克!” tutorial and now i'm trying to port the game on Android, it's my first time on Unity, now when it's going to build the APK unity tells me "Failed To Build APK" and then i get some errors, i'm attaching you the error i think it's fatal, please tell me what's wrong with it. 教程,现在我试图在Android上移植游戏,这是我第一次使用Unity,现在当它构建APK统一告诉我“无法构建APK”然后我得到一些错误,我附加你错误我认为这是致命的,请告诉我它有什么问题。

CommandInvokationFailure: Failed to build apk.
C:/Program Files/Java/jdk-9.0.1\bin\java.exe -Xmx2048M -D com.android.sdkmanager.toolsdir="C:/Android_SDK\tools" -D file.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.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
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 emoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommandSafe (System.String javaExe, System.String sdkToolsDir, System.String[] sdkToolCommand, Int32 emoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)

If you execute jdeps on your application, you would be able to see that sun.misc.BASE64Encoder has been deprecated and can be replaced with java.util.Base64 which is there since JDK 1.8. 如果在应用程序上执行jdeps ,您将能够看到sun.misc.BASE64Encoder已被弃用,并且可以替换为自JDK 1.8以来的java.util.Base64

The migration guide reads this as well : 迁移指南也会读取此内容:

A few sun.* APIs have been removed in JDK 9. Notably, sun.misc.BASE64Encode r and sun.misc.BASE64Decoder have been removed. 在JDK 9中删除了一些sun.* API。值得注意的是, sun.misc.BASE64Encode r和sun.misc.BASE64Decoder已被删除。 Instead, use the supported java.util.Base64 class, which was added in Java SE 8. 相反,请使用Java SE 8中添加的受支持的java.util.Base64类。


In your case, since you rely on third parties(android sdktools) which themselves haven't resolved this. 在你的情况下,因为你依赖第三方(android sdktools),他们自己没有解决这个问题。 I'm afraid you might have to stick with 1.8 and in the meanwhile, this can be reported to their trackers once they plan to migrate their artifacts. 我担心你可能不得不坚持1.8,同时,一旦他们计划迁移他们的文物,就可以向他们的跟踪器报告。

Of course, this also means you would have to at some point in time upgrade to using their Java 9 compatible version of the jar if and when they plan to release. 当然,这也意味着你必须在某个时间点升级到使用他们的Java 9兼容版本的jar,如果他们计划发布的话。

Update : This can be tracked on Unity#956425 for further updates. 更新 :这可以在Unity#956425上进行跟踪以获得进一步的更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM