Error reported:
Error loading /var/containers/Bundle/Application/61CD0810-9E62-452B-8129-3DAC706B56C5/HarvestBumpers.app/Frameworks/UnityFramework.framework/UnityFramework: dlopen(/var/containers/Bundle/Application/61CD0810-9E62-452B-8129-3DAC706B56C5/HarvestBumpers.app/Frameworks/UnityFramework.framework/UnityFramework, 0x0109): dependent dylib '/System/Library/Frameworks/AdServices.framework/AdServices' not found for '/private/var/containers/Bundle/Application/61CD0810-9E62-452B-8129-3DAC706B56C5/HarvestBumpers.app/Frameworks/UnityFramework.framework/UnityFramework'
The problem occurs in AdServices' not found and the AdServices.framework file is missing.
iOS 13.6 crashes, iOS 15.1/15.5 works normally
reason:
You need to manually add libraries/frameworks to the connected iOS SDK, among which AdServices is optional and only supports iOS versions 14.3 and above.
The actual setting is required, which causes exceptions on lower versions of iOS.
solve:
Make AdServices.framework optional:
Method 1: Directly modify the XCode project and change Required to Optional
Method 2: Post-processing after Unity packaging, change false to true
project.AddFrameworkToProject(frameGuid,"AdServices.framework",true)
using UnityEngine;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor.Callbacks;
using System.IO;
using System.Linq;
#if UNITY_EDITOR_OSX
using UnityEditor.iOS.Xcode;
#endif
public class BuildCallback1
{
//回调 打包后操作
[PostProcessBuild(1)]
private static void PostProcessBuildCallback(BuildTarget target,string projectPath)
{
if(target == BuildTarget.iOS)
{
#if UNITY_EDITOR_OSX
AfterBuild_IOS(projectPath);
#endif
}
}
#if UNITY_EDITOR_OSX
private static void AfterBuild_IOS(string projectPath)
{
//修改设置属性
string projPath = PBXProject.GetPBXProjectPath(projectPath);
PBXProject project = new PBXProject();
project.ReadFromString(File.ReadAllText(projPath));
string frameGuid = project.GetUnityFrameworkTargetGuid();
//True if the framework is optional (i.e. weakly linked), false if the framework is required.
project.AddFrameworkToProject(frameGuid,"AdServices.framework",true);
/*
* 其他后处理操作
*/
File.WriteAllText(projPath,project.WriteToString());
Debug.Log("Xcode 后续处理完成");
}
#endif
}