• iOS适配Unity-2019


    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".
    
    • 1

    解决方式

    此问题是由于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");
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    设置中如果报如下错误,可以采用设置为$(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.
    
    • 1
    • 2
    • 3

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

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

    请添加图片描述

    问题二

    错误描述

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

    解决方式

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

    string mainAppPath = Path.Combine(projectPath, "MainApp", "main.mm");
    string mainContent = File.ReadAllText(mainAppPath); 
    string newContent = mainContent.Replace("#include ", @"#include ""../UnityFramework/UnityFramework.h""");
    File.WriteAllText(mainAppPath, newContent);
    
    • 1
    • 2
    • 3
    • 4

    问题三

    错误描述

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

    解决方式

    如果没有使用到这个服务,可以设置一个假的参数,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");
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    问题三

    错误描述

    在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/

  • 相关阅读:
    Java多线程开发系列之六:无限分解流----Fork/Join框架
    【设计模式】Java设计模式 - 装饰者模式
    PMC在制造企业中发挥哪些价值?
    iris(golang)连接mysql数据库
    ScyllaDB获4300万美元融资,NoSQL数据库市场再掀热潮!
    Codeforces Round 932 (Div. 2) ---- E. Distance Learning Courses in MAC ---- 题解
    flink技术总结待续
    MySQL 事务和锁
    利用AI+大数据的方式分析恶意样本(四十一)
    【Java】异常处理
  • 原文地址:https://blog.csdn.net/qin_shi/article/details/128057426