From 0c80981921069302d953133832f8e6f262eb7d9e Mon Sep 17 00:00:00 2001 From: the9an Date: Sun, 10 Aug 2025 00:02:09 +0900 Subject: [PATCH] fix(ios): properly embed Facebook SDK xcframeworks to prevent startup crash --- UnitySDK/Assets/Editor/AddFramework.cs | 70 +++++++++++++++++++++ UnitySDK/Assets/Editor/AddFramework.cs.meta | 3 + 2 files changed, 73 insertions(+) create mode 100644 UnitySDK/Assets/Editor/AddFramework.cs create mode 100644 UnitySDK/Assets/Editor/AddFramework.cs.meta diff --git a/UnitySDK/Assets/Editor/AddFramework.cs b/UnitySDK/Assets/Editor/AddFramework.cs new file mode 100644 index 00000000..a4fe9e99 --- /dev/null +++ b/UnitySDK/Assets/Editor/AddFramework.cs @@ -0,0 +1,70 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. All rights reserved. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to use, + * copy, modify, and distribute this software in source code or binary form for use + * in connection with the web services and APIs provided by Facebook. + * + * As with any software that integrates with the Facebook platform, your use of + * this software is subject to the Facebook Developer Principles and Policies + * [http://developers.facebook.com/policy/]. This copyright notice shall be + * included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +using UnityEditor; +using UnityEditor.Callbacks; + +#if UNITY_IOS +using UnityEditor.iOS.Xcode; +using UnityEditor.iOS.Xcode.Extensions; +#endif + +namespace Facebook.Unity.PostProcess +{ + /// + /// Post-build processor that ensures required Facebook iOS frameworks are embedded into the Xcode project. + /// This version fixes app crash at startup by correctly embedding and signing .xcframeworks, + /// and setting search paths for runtime resolution. + /// + public static class AddFramework + { + [PostProcessBuild(999)] + public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject) + { +#if UNITY_IOS + string[] frameworks = + { + "FBAEMKit", + "FBSDKCoreKit", + "FBSDKCoreKit_Basics", + "FBSDKGamingServicesKit", + "FBSDKLoginKit", + "FBSDKShareKit" + }; + + string projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject); + PBXProject proj = new PBXProject(); + proj.ReadFromFile(projPath); + string unityMainTarget = proj.GetUnityMainTargetGuid(); + + foreach (var framework in frameworks) + { + var frameworkName = $"{framework}.xcframework"; + var src = Path.Combine("Pods", framework, "XCFrameworks", frameworkName); + var frameworkPath = proj.AddFile(src, src); + proj.AddFileToBuild(unityMainTarget, frameworkPath); + proj.AddFileToEmbedFrameworks(unityMainTarget, frameworkPath); + } + + proj.WriteToFile(projPath); +#endif + } + } +} diff --git a/UnitySDK/Assets/Editor/AddFramework.cs.meta b/UnitySDK/Assets/Editor/AddFramework.cs.meta new file mode 100644 index 00000000..cbc3c34e --- /dev/null +++ b/UnitySDK/Assets/Editor/AddFramework.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c299de67aafc4ae78e5a7ec1922b4081 +timeCreated: 1754750516 \ No newline at end of file