构建iOS包
构建iOS包
在构建iOS包时,遇到了挺多问题,因此记录下来,以备不时之需
环境
- Unity:2020.3.26f1
- XCode:13.2.1(13C100)
导出xcodeproj
使用
UnityEditor.BuildPipeline.BuildPlayer
构建即可,然后就导出xcodeproj。
设置xcodeproj配置
PBXProject工具
PBXProject
是Unity用于修改导出的xcode工程参数的工具。 P.S.需要安装iOSSupport
//初始化PBXProject
UnityEditor.iOS.Xcode.PBXProject project = new UnityEditor.iOS.Xcode.PBXProject();
string projectName = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(projectPath); //使用BuildPlayer的构建目录地址获取PBX项目地址
project.ReadFromFile(projectName); //读取项目配置文件
//修改配置的逻辑....
project.WriteToFile(projectName); //把修改后的配置写入
添加引用库
某些第三方SDK需要加入引用的库。 例如
Bugly
,需要增加以下库:
- libz.tbd
- libc++.tbd
- Security.framework
- SystemConfiguration.framework
- JavaScriptCore.framework
然后可以使用AddFrameworkToProject
进行添加这些库。
//先获取UnityFramework的targetGUID,用于指定需要添加库的配置
string frameworkGUID = project.GetUnityFrameworkTargetGuid();
project.AddFrameworkToProject(frameworkGUID, "libz.tbd", false);
project.AddFrameworkToProject(frameworkGUID, "libc++.tbd", false);
...
设置属性
需要设置某些构建属性时,需要用到
SetBuildProperty
方法。 例如关闭Bitcode
//获取UnityMain和UnityFramework的targetGUID,用于指定需要修改属性的配置
string mainTargetGUID = project.GetUnityMainTargetGuid();
string frameworkGUID = project.GetUnityFrameworkTargetGuid();
//Bitcode需要都关闭
project.SetBuildProperty(mainTargetGUID, "ENABLE_BITCODE", "No"); //用于开启关闭Bitcode
project.SetBuildProperty(frameworkGUID, "ENABLE_BITCODE", "No"); //用于开启关闭Bitcode
//发布版时,需要修改签名类型
project.SetBuildProperty(mainTargetGUID, "CODE_SIGN_IDENTITY", "Apple Distribution"); //用于设置成发布状态
project.SetBuildProperty(mainTargetGUID, "CODE_SIGN_IDENTITY[sdk=iphoneos*]", "Apple Distribution"); //用于设置成发布状态
project.SetBuildProperty(mainTargetGUID, "PROVISIONING_PROFILE_SPECIFIER", m_Setting.ProvisioningProfileName); //需要设置ProvisioningProfile
ExportOptions
- Method:方式
- app-store
- enterprise
- ad-hoc
- development
- BundleID:包名
- ProvisioningProfile:证书名字
- TeamID:证书的TeamID
- Certificate:签名证书
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC " -//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>compileBitcode</key>
<false/>
<key>destination</key>
<string>export</string>
<key>manageAppVersionAndBuildNumber</key>
<false/>
<key>method</key>
<string>${METHOD}</string>
<key>provisioningProfiles</key>
<dict>
<key>${BUNDLE_ID}</key>
<string>${PROVISIONING_PROFILE}</string>
</dict>
<key>signingCertificate</key>
<string>${CERTIFICATE}</string>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>${TEAM_ID}</string>
<key>thinning</key>
<string><none></string>
</dict>
</plist>
错误处理
环境错误
The data couldn’t be read because it isn’t in the correct format
https://www.jianshu.com/p/103f414fa870 https://stackoverflow.com/questions/58272706/error-exportarchive-the-data-couldn-t-be-read-because-it-isn-t-in-the-correct
sqlite3环境问题导致的报错,执行如下指令即可:
gem list | grep sqlite3
gem install sqlite3 --platform=ruby
rvm use system --default
类型错误
Error Domain=IDEProfileLocatorErrorDomain Code=4 “No “iOS App Development” profiles for team ‘*****’ …..
确保provisioning profile
中填入的类型正确
授权问题
“error: “Unity-iPhone” requires a provisioning profile. Select a provisioning profile in the Signing & Capabilities editor. (in target ‘Unity-iPhone’ from project ‘Unity-iPhone’)”
一般是没有登录provisioning profile
对应的开发者账号,或者是没有安装provisioning profile
对应的Capabilities
评论
还沒有留言。