gpt4 book ai didi

c# - Unity 无法构建 apk Android

转载 作者:太空宇宙 更新时间:2023-11-03 12:27:12 25 4
gpt4 key购买 nike

我跟着统一“坦克!”教程,现在我正在尝试将游戏移植到 Android 上,这是我第一次使用 Unity,现在当它要构建 APK 时,unity 告诉我“构建 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)

最佳答案

如果您在应用程序上执行 jdeps,您将能够看到 sun.misc.BASE64Encoder 已被弃用,可以替换为 java.util.Base64 从 JDK 1.8 开始就有了。

migration guide 也读取这个:

A few sun.* APIs have been removed in JDK 9. Notably, sun.misc.BASE64Encoder and sun.misc.BASE64Decoder have been removed. Instead, use the supported java.util.Base64 class, which was added in Java SE 8.


在你的情况下,因为你依赖第三方(android sdktools),他们自己还没有解决这个问题。恐怕您可能不得不坚持使用 1.8,与此同时,一旦他们计划迁移他们的 Artifact ,这可以报告给他们的跟踪器。

当然,这也意味着如果他们计划发布,您将不得不在某个时间点升级到使用他们的 Java 9 兼容版本的 jar

更新:这可以在 Unity#956425 上进行跟踪以获取进一步的更新。

关于c# - Unity 无法构建 apk Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46978301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com