Unity自动化Xcode配置及接入SDK踩坑记录

Unity自动化Xcode配置及接入SDK踩坑记录,第1张

PBXProject能做什么 添加依赖库修改BuildSettings修改Plist文件添加包文件Bundle文件添加库文件,头文件Search Path添加自己的OC代码

例如以下要求:

代码示例
using System;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;

namespace EB.Editor
{
    public static class PostProcess
    {

        [PostProcessBuild(100)]
        public static void IOSProcess(BuildTarget target, string path)
        {
            EB.Debug.Log("IOSProcess111111111111111111");
            UnityEngine.Debug.LogFormat("结束打包时间:{0}",DateTime.Now.ToString());
            if (target != BuildTarget.iOS)
            {
                return;
            }
            UnityEngine.Debug.LogFormat("PostProcess {0}, {1}", target, path);

            PBXProject proj = new PBXProject();
            string project_file_name = PBXProject.GetPBXProjectPath(path);
            proj.ReadFromFile(project_file_name);

            string guid = proj.GetUnityFrameworkTargetGuid();

#region 自动添加framework
            proj.AddFrameworkToProject(guid, "StoreKit.framework", false);
            proj.AddFrameworkToProject(guid, "CoreTelephony.framework", false);
            proj.AddFrameworkToProject(guid, "libz.tbd", false);
            proj.AddFrameworkToProject(guid, "libc++.tbd", false);
            proj.AddFrameworkToProject(guid, "libsqlite3.0.tbd", false);
            proj.AddFrameworkToProject(guid, "libsqlite3.tbd", false);
            #endregion

            #region UseSymbols
            proj.SetBuildProperty(guid, "DEBUG_INFORMATION_FORMAT", "dwarf-with-dsym");
            proj.SetBuildProperty(guid, "GCC_GENERATE_DEBUGGING_SYMBOLS", "YES");
            proj.SetBuildProperty(guid, "COPY_PHASE_STRIP", "NO");
            proj.SetBuildProperty(guid, "GCC_ENABLE_OBJC_EXCEPTIONS", "YES");
            proj.SetBuildProperty(guid, "GCC_ENABLE_CPP_EXCEPTIONS", "YES");
            proj.SetBuildProperty(guid, "ENABLE_BITCODE", "NO");
            proj.AddBuildProperty(guid, "OTHER_LDFLAGS", "-ObjC -lz");
            proj.SetBuildProperty(guid, "SWIFT_VERSION", "5.0");
            
            //XCFramework 
            proj.SetBuildProperty(guid,"VALIDATE_WORKSPACE","YES");
            #endregion

            proj.WriteToFile(project_file_name);
            UnityEngine.Debug.LogFormat("PostProcess {0}, {1} finished", target, path);
        }
    }
}

Unity更新后Xcode的项目结构:

Xcode项目结构

从 Unity 2019.3 开始,已弃用 PBXProject.GetUnityTargetName 和 pbxProject->TargetGuidByName(“Unity-iPhone”)。接下来可以改用 pbxProject->GetUnityFrameworkTargetGuid() 或 pbxProject->GetUnityMainTargetGuid():

// 已弃用
string targetGuid = proj.TargetGuidByName("Unity-iPhone");
string targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName());

// 改为以下调用之一
string targetGuid = proj.GetUnityFrameworkTargetGuid(); 
string targetGuid = proj.GetUnityMainTargetGuid();
其他错误

升级XCode12.3报错 Building for , but the linked and embedded framework was built for iOS + iOS Simulator
打开项目路径 - Build Setting > Build Options > Validate WorkSpaceValidate WorkSpace 设置为 true

Build Success 但是 Unable to install
第三方嵌入方式设置不对 Do not Embed

错误:Symbol not found: OBJC_CLASS$_JSContext
出现这种错误,就两种原因:

缺少对应的库

Unity端定义了IOS端的外部方法,而在IOS这边找不到,删掉Unity的外部方法或者在IOS端补充对应的方法。

缺少包文件Bundle (资源文件包)
检查导入的SDK中所有的bundle文件是否勾选iOS选项,如果没有勾选,在Unity编译出Xcode工程后会缺失。

如果还找不到的话,将Bundle文件手动拖入,会自动导入

XCode 动态库未签名问题的解决

code signature in (*.dylib) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed

需要将KSAdSDK.framework的Embed修改为Embed&Sign,同时注意到添加到主工程

上传appstore失败

Invalid Bundle. The bundle at ‘ProductName.app/Frameworks/UnityFramework.framework’ containsdisallowed file ‘Frameworks’:. With error code STATE_ERROR.VALIDATION_ERROR.90206 for id


主工程设置build settings》Always Embed Swift Standard Libraries: YES extension 》 Always Embed Swift Standard Libraries: NO

缺少合规证明
   PlistDocument plist = new PlistDocument();
   string info_plist_file_name = Path.Combine(path, "Info.plist");
   plist.ReadFromFile(info_plist_file_name);
   // plist.root["LSHasLocalizedDisplayName"] = new PlistElementString("Yes");
   plist.root.SetBoolean("ITSAppUsesNonExemptEncryption", false);
   plist.WriteToFile(info_plist_file_name);

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/990526.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存