iOS适配Unity-2019

2 篇文章 0 订阅

iOS适配Unity-2019

背景

由于2019起,Unity的Xcode工程,更改了项目结构。

Unity 2018的结构:

请添加图片描述

可以看Targets只有一个Unity-iPhone,Unity-iPhone直接依赖管理三方库。

Unity2019以后:

请添加图片描述

Targets多了一个UnityFramework,UnityFramework管理三方库,Unity-iPhone依赖于UnityFramwork。

所以升级后,会有若干的问题,以下是对问题的解决方式。

问题一

错误描述

error: exportArchive: Missing signing identifier at "/var/folders/fr//T/XcodeDistPipeline.~~~/Root/Payload/XX.app/Frameworks/UnityFramework.framework/Frameworks/libswiftAVFoundation.dylib".

解决方式

此问题是由于ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES 在UnityFramework为YES导致,需要设置为NO。

正确的设置为:

Unity-iPhone的ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES 为YES。

Unity-UnityFramework的ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES 为NO。

请添加图片描述

设置代码如下:

var projPath = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(projectPath);
var xcodeProject = new UnityEditor.iOS.Xcode.PBXProject();
xcodeProject.ReadFromFile(projPath);
                
string xcodeTarget = xcodeProject.GetUnityMainTargetGuid();
var unityTargetGuid = xcodeProject.GetUnityFrameworkTargetGuid();                
string projectGuid = xcodeProject.ProjectGuid();

//设置Project
xcodeProject.SetBuildProperty(projectGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "NO");
//设置Unity-iPhone
xcodeProject.SetBuildProperty(unityTargetGuid, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "NO");//设置Project
//设置UnityFramework
xcodeProject.SetBuildProperty(xcodeTarget, "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "NO");

设置中如果报如下错误,可以采用设置为$(inherited)

[!] The Unity-iPhone [Release] target overrides the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES build setting defined in Pods/Target Support Files/Pods-Unity-iPhone/Pods-Unity-iPhone.release.xcconfig'. This can lead to problems with the CocoaPods installation     
- Use the $(inherited)` flag, or
- Remove the build settings from the target.

ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES 的作用:Xcode把Swift的标准库嵌入到Target中。

$(inherited) ********的作用:继承上层的配置(或者基类的配置)。查看方式如图

请添加图片描述

问题二

错误描述

Xcode build Error : 'UnityFramework/UnityFramework.h' file not found

解决方式

我在Xcode 14.1上未发现此问题,但是在Xcode 13.2上发现了此问题。解决方式为修改为相对引用

string mainAppPath = Path.Combine(projectPath, "MainApp", "main.mm");
string mainContent = File.ReadAllText(mainAppPath); 
string newContent = mainContent.Replace("#include <UnityFramework/UnityFramework.h>", @"#include ""../UnityFramework/UnityFramework.h""");
File.WriteAllText(mainAppPath, newContent);

问题三

错误描述

level=fatal msg="Please provide an auth token with USYM_UPLOAD_AUTH_TOKEN environment variable"

解决方式

如果没有使用到这个服务,可以设置一个假的参数,2019以前的Unity只需要对主Target设置即可,但是2019及以后的版本,要对UnityFramework也要设置下。

var projPath = UnityEditor.iOS.Xcode.PBXProject.GetPBXProjectPath(projectPath);
var xcodeProject = new UnityEditor.iOS.Xcode.PBXProject();
xcodeProject.ReadFromFile(projPath);
                
string xcodeTarget = xcodeProject.GetUnityMainTargetGuid();
var unityTargetGuid = xcodeProject.GetUnityFrameworkTargetGuid();

xcodeProject.SetBuildProperty(xcodeTarget, "USYM_UPLOAD_AUTH_TOKEN", "FakeToken");
xcodeProject.SetBuildProperty(unityTargetGuid, "USYM_UPLOAD_AUTH_TOKEN", "FakeToken");

问题三

错误描述

在Unity端,发现对iOS工程的buildSetting设置无效。

解决方式

此问题的排查思路,可以尝试修改[PostProcessBuild(999)] 的优先级试下,有可能为其他的SDK把起进行了再次修改。

Apple 参数设置参考:https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html

参考链接:

https://lsnumber1.github.io/2022/11/26/Unity2019-%E9%80%82%E9%85%8DiOS/#/%E8%83%8C%E6%99%AF

https://blog.mzying.com/index.php/archives/191/

https://forum.unity.com/threads/xcode-build-error-unityframework-unityframework-h-file-not-found.838318/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值