目录

Unity游戏打包打包常见报错含AndroidiOS

目录

Unity游戏打包——打包常见报错(含Android、iOS)

本文由 NRatel 历史实操笔记整理而来,可能持续补充。

1、网络问题,Git报错: Empty reply from server

https://i-blog.csdnimg.cn/direct/3f97820059dc474182aa8bf0ca600aec.png

原因:网络问题,检查网络和vpn

解决:重试一次即可

2、网络问题,Git报错:Could not resolve host: xxxxx

https://i-blog.csdnimg.cn/direct/4239389f231f403f99265c9b71206697.png

原因:网络问题

解决:开启vpn (域名代理)/切换vpn 节点尝试

3、命令行启动Unity时报错:‘Library/SourceAssetDB’ with error 28 No space left on device

https://i-blog.csdnimg.cn/direct/132849be0eb04e629594bdbf877b9e16.png

原因:打包机存储空间不足?实际查看存储空间是足的,应该是其他问题。

解决:重启打包机即可解决,但一段时间后可能再次出现。

有一次,发现是启动Unity时闪退了,删除 Library 和 Temp 目录也不起作用。

最后,删除Assets下所有资源然后启动了。再加回资源就好了。

怀疑 unity 在资源导入时发生了什么死锁。

4、FileNotFoundError: [Errno 2] No such file or directory: ‘/Users/nratel/.jenkins/workspace/BuildApp_Android/NativeProject/XXXXX’

原因:未正常导出Unity工程为Android工程,且Unity没返回错误码,进入了下一步,导致报错。

正常情况下,一般有导出有错,Unity都会返回错误码使流程中断,但还有一些情况还是不会。

解决:检查是否有C#脚本报错(搜索关键字error)、证书是否过期(经常)、检查PlayerSettings设置是否不正确。

5、【安卓】* What went wrong:

Execution failed for task ‘:launcher:bundleReleaseResources’.

A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade

   > AAPT2 aapt2-4.0.1-6197926-osx Daemon #0: Link timed out, attempting to stop daemon.

     This should not happen under normal circumstances, please file an issue if it does.

https://i-blog.csdnimg.cn/direct/928aadde925f439aa096c12568b481ac.png

Link timed out 原因不明,大概率网络问题,重试又可以了。

6、【安卓】* What went wrong:

Execution failed for task ‘:launcher:dexBuilderDebug’.

java.lang.UnsupportedOperationException: This feature requires ASM7

https://i-blog.csdnimg.cn/direct/1ce84b3edb144be88cee013e4e23336e.png

原因:打完一次 release aab 包后,没有 gralde clean 就打 debug 包时偶现,

解决:启用打包 gralde clean 即可。

7、【安卓】FAILURE: Build failed with an exception.

  • What went wrong:

Could not determine the dependencies of task ‘:launcher:compileDebugJavaWithJavac’.

Could not resolve all dependencies for configuration ‘:launcher:debugRuntimeClasspath’.

   > Could not determine artifacts for androidx.core:core:1.3.2

      > Could not get resource ‘ ’.

         > Could not HEAD ‘ ’.

            > Remote host closed connection during handshake

  • Try:

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.

  • Get more help at

BUILD FAILED in 1m 30s

原因:公司网络/vpn问题,不能解析下载路径的域名。

解决:当前vpn使用全局代理(网卡),但不使用域名全代。

8、报错:Error building Player: BuildFailedException: You must run HybridCLR/Installer after upgrading package

https://i-blog.csdnimg.cn/direct/fcb619ada673477c8a0b873ee5efca0f.png

原因:更新 HybridCLR后,未在打包机执行 Install。

注意,把安装内容 HybridCLRData/LocalIl2CppData-OSXEditor 提交到git,防止重打包时被git清空。

9、【安卓】报错

FAILURE: Build failed with an exception.

  • What went wrong:

Execution failed for task ‘:launcher:processDebugResources’. > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade > AAPT2 aapt2-4.0.1-6197926-osx Daemon #1: Unexpected error during link, attempting to stop daemon. This should not happen under normal circumstances, please file an issue if it does.

https://i-blog.csdnimg.cn/direct/4dc48bc406ad4f778a34891fbf3eed23.png

原因:将安卓 Target API Level 从33提升为34导致。

解决:解决:android sdk、build-tools、gralde、gradle-plugin、jdk、ndk..,都要装成匹配的版本。

10、【安卓】导出工程时报错

https://i-blog.csdnimg.cn/direct/565fb7cb074a49e09bc8dfca93022391.png

原因,将不同Gradle project template version 的unity导出到同一目录所致,应该先清理后再导出。可能发生在分支切换时。

11、Unity 打开新项目,或清除 Library 后重打包时,执行命令卡住不动。

https://i-blog.csdnimg.cn/direct/b1be4941cec84d5c93376bd840f962e1.png

卡死在 AssemblyUpdater.exe update -a 时。

参考:

解决:在 unity 命令行调用时,增加 -disable-assembly-updater

12、【iOS】报错:error: “Unity-iPhone” requires a provisioning profile. Select a provisioning profile in the Signing & Capabilities editor. (in target ‘Unity-iPhone’ from project ‘Unity-iPhone’)

https://i-blog.csdnimg.cn/direct/27905f46426c4e9fb38f74eccfd49950.png

解决:在取得正式证书之前,先使用 Automatically Sign 方式

https://i-blog.csdnimg.cn/direct/b68878143f7a4113a90fe58033bb78ad.png

先在导出项目上手动设置Team,

然后查看 project.pbxproj(项目名.xcodeproj-> 右击显示包内容 -> project.pbxproj

),可知 TeamId

https://i-blog.csdnimg.cn/direct/0b170a67e47145a8ad339e922a8b9541.pnghttps://i-blog.csdnimg.cn/direct/d05904f121054d3a8540b9ceaf903e07.png

13、【iOS】警告 warning: The iOS deployment target ‘IPHONEOS_DEPLOYMENT_TARGET’ is set to 11.0, but the range of supported deployment target versions is 12.0 to 17.4.99. (in target ‘Unity-iPhone’ from project ‘Unity-iPhone’)

解决:在Unity中,将 Target minimum iOS Version 设为12

14、【iOS】报错:error: no such module ‘FBSDKCoreKit’ import FBSDKCoreKit

https://i-blog.csdnimg.cn/direct/1a2f731a8d73460f9c03edd2d1c859e4.png

原因:facebook 使用 pod 管理依赖,打包时应使用 pod工作空间,而非原始xcode工程。

解决:更新 pod 并使用 pod 工作空间构建。

15、【iOS】报错:xcodebuild: error: The flag -archivePath is required when specifying -exportArchive.

https://i-blog.csdnimg.cn/direct/4ab8539b34644be3b0d159983ce15c7f.png

原因:当执行xcodebuild -exportArchive 时,必须指定 -archivePath、-exportPath。

建议:在xcodebuild archive 和 xcodebuild -exportArchive 都显示指定 -archivePath。

在xcodebuild -exportArchive 时,也显示指定 -exportPath。

虽然 xcodebuild archive 时,可以不指定生成位置,默认生成在:

~/Library/Developer/Xcode/Archives/日期/时分.xcarchive

如:~/Library/Developer/Xcode/Archives/2024-6-1/19.51.xcarchive

15、【iOS】报错:xcodebuild: error: The flag -exportOptionsPlist is required when specifying -exportArchive.

https://i-blog.csdnimg.cn/direct/cb7f5bc9480547388502645b2024b284.png

原因:当执行xcodebuild -exportArchive 时,必须指定 -exportOptionsPlist。

由 -exportOptionsPlist 指定的 .plist文件其内容可以填写内容,见 xcodebuild -h。

对于 development 的 .plist  暂只指定以下项:

method: development

signingStyle: automatic

teamID: xxxxxxxxxx (xocode上的非开发者账号)

对于 出正式包:指定以下项:

method: app-store

compileBitcode: true

uploadBitcode: true

uploadSymbols: true

signingStyle: automatic

provisioningProfiles:

provisioningProfiles

com.yourcompany.yourapp YourProvisioningProfileName

注意,xcodebuild -exportArchive 无需指定 -workspace、-scheme -configuration

16、【iOS】报错:error: No profiles for ‘com.xxx.xxx’ were found: Xcode couldn’t find any iOS App Development provisioning profiles matching ‘com.xxx.xxx’. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild. (in target ‘Unity-iPhone’ from project ‘Unity-iPhone’)

https://i-blog.csdnimg.cn/direct/16ecdf4a83f7436994dc9357030b7c74.png

原因:更换了包名,报错。这个包名未注册到指定的Team中。

解决:使用运营给的 包名、签名文件

17、【iOS】报错:error: Provisioning profile “xxxxxxxxx” doesn’t include the currently selected device “xxx的MacBook Pro” (identifier 00006000-001A498C1432801E). (in target ‘Unity-iPhone’ from project ‘Unity-iPhone’)

https://i-blog.csdnimg.cn/direct/c356a877f8a940ca9894f6f58be59cea.png

在xcode 中直接 Product archive 可以成功,

但在相同情形下,执行以下命令行却失败

xcodebuild archive -workspace Unity-iPhone.xcworkspace -scheme Unity-iPhone -configuration Debug

原因:两者的 -destination 和 -configuration 不一致,

在 -destination 为本机mac 时,若签名不包含本机id 则报此错。

若有需要,应让运营添加执行 mac id 重新生成证书。

解决:设置正确的 -destination 和 -configuration。

18、【iOS】报错:error: exportArchive: No “iOS App Development” profiles for team ‘XXX TECHNOLOGY CO., LIMITED’ matching ‘xxxxxxxxxxxx’ are installed.

https://i-blog.csdnimg.cn/direct/14549299c8044d02b495b134e34554dc.png

原因:optionsPlist 配置错误。

解决:正确的包含:method、signingStyle、teamID、provisioningProfiles。

19、【iOS】报错: error: Provisioning profile “xxxxxxxxxxxx” doesn’t include signing certificate “Apple Development: xxxx (xxxxxxx)”. (in target ‘Unity-iPhone’ from project ‘Unity-iPhone’)

https://i-blog.csdnimg.cn/direct/f5b04e984c5642a58fe07e7d179f75db.png

原因:在Unity 中指定的与 archive 时指定的不一致了。

https://i-blog.csdnimg.cn/direct/884ee935e3a34b1984b9276397fd3455.png

解决:修改打包脚本,统一在Unity中指定。

20、【iOS】报错:xcodebuild: error: ‘Unity-iPhone.xcworkspace’ does not exist.

https://i-blog.csdnimg.cn/direct/16f683547a65414d8078656c713cd7e9.png

排查:

  1. 确保 EDM4U 中导出类型为 pod工程
  2. 确保导出和初始化pod工程顺利。 打包日志中搜索“pod”

Error running CocoaPods. Please ensure you have at least version 1.0.0.  You can install CocoaPods with the Ruby gem package manager:

sudo gem install -n /usr/local/bin cocoapods

pod setup

‘pod –version’ returned status: 1

https://i-blog.csdnimg.cn/direct/7578a979e4e940d0919fe244b0b5897f.png

原因和解决:重装 brew,导致ruby和pod坏了,需重装。

最终确认 pod –version 正确即可。

21、【iOS】报错同上:xcodebuild: error: ‘Unity-iPhone.xcworkspace’ does not exist.

搜索 pod查看,发现 timeout。 使用命令行进入工程目录 手动执行 pod install 同样如此。

https://i-blog.csdnimg.cn/direct/4abf33ab992b4f77b26545f5a674d8c7.png

原因是:新接了一些sdk后,需要重新下载这些库,但因网络问题无法下载,开启vpn 或启用代理后解决。(可手动执行一次,后续无需重复下载)

运行时报错一:

Library not loaded: @rpath/FBAEMKit.framework/FBAEMKit

解决:(Facebook Dependencies.xml 添加 addToAllTargets=“true” 到每行):

运行时报错二:

2024-06-06 21:33:27.747087+0800 LegendsMatch[7234:623209] *** Terminating app due to uncaught exception ‘GADInvalidInitializationException’, reason: ‘The Google Mobile Ads SDK was initialized without an application ID. Google AdMob publishers, follow instructions at https://googlemobileadssdk.page.link/admob-ios-update-plist to set a valid application ID. Google Ad Manager publishers, follow instructions at https://googlemobileadssdk.page.link/ad-manager-ios-update-plist.’

https://i-blog.csdnimg.cn/direct/a978878621a144508720a7ecff82d52d.png

原因:Admob 在PListProcessor.cs 中指定GADApplicationIdentifier,但写死了一些依赖的文件路径。这是自己整理目录产生的问题。

解决:注意最好,保持 Admob 导入的原始目录。

https://i-blog.csdnimg.cn/direct/b3d8ba6dc19940a2b965fc405ff7ed04.pnghttps://i-blog.csdnimg.cn/direct/9f7d277be7054ac8a0ebda06abd3c57b.png