问题
在从 UE4.24 升级到 UE4.26 后,想打包安卓,删除了以前的 NDK 然后根据官网指示安装新的 NDK ,在打包时提示打包失败,Log 关键内容如下。
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): ====2021-08-09 14:35:59====PERFORMING FINAL APK PACKAGE OPERATION=====-armv7===========================================
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): Fixing minSdkVersion; NDK level above 19 requires minSdkVersion of 21 (arch=armv7)
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)):
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): Creating rungradle.bat to work around commandline length limit (using unused drive letter Z:)
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): Making .apk with Gradle...
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/6.1.1/userguide/gradle_daemon.html.
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): Daemon will be stopped at the end of the build stopping after processing
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): Build-tool 31.0.0 is missing DX at C:\Users\_Redstone_c_\AppData\Local\Android\Sdk\build-tools\31.0.0\dx.bat
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): File C:\Users\_Redstone_c_\.android\repositories.cfg could not be loaded.
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): Build-tool 31.0.0 is missing DX at C:\Users\_Redstone_c_\AppData\Local\Android\Sdk\build-tools\31.0.0\dx.bat
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)):
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): FAILURE: Build failed with an exception.
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)):
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): * What went wrong:
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): > Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)):
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): * Try:
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)):
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): * Get more help at https://help.gradle.org
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)):
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): BUILD FAILED in 9s
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): ERROR: cmd.exe failed with args /c "C:\Users\_Redstone_c_\Documents\Unreal Projects\RaspberryVehicle\Intermediate\Android\armv7\gradle\rungradle.bat" :app:assembleDebug
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): Took 12.6688736s to run UnrealBuildTool.exe, ExitCode=6
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): UnrealBuildTool failed. See log for more details. (C:\Users\_Redstone_c_\AppData\Roaming\Unreal Engine\AutomationTool\Logs\C+Program+Files+Epic+Games+UE_4.26\UBT-RaspberryVehicle-Android-Development.txt)
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): AutomationTool exiting with ExitCode=6 (6)
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): BUILD FAILED
PackagingResults: Error: cmd.exe failed with args /c "C:\Users\_Redstone_c_\Documents\Unreal Projects\RaspberryVehicle\Intermediate\Android\armv7\gradle\rungradle.bat" :app:assembleDebug
PackagingResults: Error: Unknown Error
解决
刚开始看到以下信息,指示 Build-tool 31.0.0 损坏需要重新安装。
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): > Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.
按照提示在 SDK Manager 中重新安装 Build-tool 31.0.0 后报错依旧。
后来根据 Stack Overflow 上 这个提问 的答案,注意到上面有文件丢失提示。
UATHelper: Packaging (Android (Multi:ASTC,DXT,ETC2)): Build-tool 31.0.0 is missing DX at C:\Users\_Redstone_c_\AppData\Local\Android\Sdk\build-tools\31.0.0\dx.bat
根据 Stack Overflow 上的回答, SDK 缺失文件为 dx.bat 和 dx.jar ,他们被错误命名为 d8.bat 和 d8.jar ,分别存在于以下两个目录,将文件重命名后打包成功。
C:\Users\[用户名]\AppData\Local\Android\Sdk\build-tools\31.0.0
C:\Users\[用户名]\AppData\Local\Android\Sdk\build-tools\31.0.0\lib