#if UNITY_EDITOR && UNITY_IOS using System.IO; using System.Collections.Generic; using UnityEditor; using UnityEditor.Build; using UnityEditor.iOS.Xcode; using UnityEngine; internal static class LocalFacebookSdk { internal static void Configure(PBXProject project, string mainTarget, string frameworkTarget, string buildPath) { string sdkRoot = Path.Combine(Application.dataPath, "FacebookSDK/Plugins/iOS/XCFrameworks"); string[] modules = { "FBAEMKit", "FBSDKCoreKit_Basics", "FBSDKCoreKit", "FBSDKLoginKit", "FBSDKShareKit", "FBSDKGamingServicesKit" }; foreach (string module in modules) { string assetPath = "Assets/FacebookSDK/Plugins/iOS/XCFrameworks/" + module + ".xcframework"; var importer = AssetImporter.GetAtPath(assetPath) as PluginImporter; if (importer == null || !importer.GetCompatibleWithPlatform(BuildTarget.iOS)) throw new BuildFailedException("Local Facebook SDK must be enabled for iOS: " + assetPath); // PluginImporter exports and links the complete static XCFramework. // Static archives must not be added to Embed Frameworks. string xcframework = Path.Combine(sdkRoot, module + ".xcframework"); if (!File.Exists(Path.Combine(xcframework, "Info.plist"))) throw new BuildFailedException("Missing local Facebook XCFramework: " + xcframework); // Static linking does not copy framework resources. Preserve manifests // in separate app resource bundles for Xcode privacy report aggregation. string manifest = Path.Combine(xcframework, "ios-arm64_arm64e/" + module + ".framework/PrivacyInfo.xcprivacy"); if (!File.Exists(manifest)) { if (module != "FBSDKGamingServicesKit") throw new BuildFailedException("Missing Facebook privacy manifest: " + manifest); continue; } string bundlePath = "FacebookSDKResources/" + module + "Privacy.bundle"; string bundleDirectory = Path.Combine(buildPath, bundlePath); Directory.CreateDirectory(bundleDirectory); File.Copy(manifest, Path.Combine(bundleDirectory, "PrivacyInfo.xcprivacy"), true); var info = new PlistDocument(); info.root.SetString("CFBundleIdentifier", "com.facebook.sdk." + module.Replace("_", "-") + ".privacy"); info.root.SetString("CFBundleName", module + "Privacy"); info.root.SetString("CFBundlePackageType", "BNDL"); info.root.SetString("CFBundleVersion", "1"); info.WriteToFile(Path.Combine(bundleDirectory, "Info.plist")); string bundleGuid = project.FindFileGuidByProjectPath(bundlePath); if (string.IsNullOrEmpty(bundleGuid)) bundleGuid = project.AddFile(bundlePath, bundlePath, PBXSourceTree.Source); project.AddFileToBuild(mainTarget, bundleGuid); } foreach (string framework in new[] { "Security.framework", "SafariServices.framework", "AuthenticationServices.framework", "AdSupport.framework", "StoreKit.framework", "WebKit.framework", "Accelerate.framework" }) project.AddFrameworkToProject(frameworkTarget, framework, false); project.AddFrameworkToProject(frameworkTarget, "AdServices.framework", true); foreach (string flag in new[] { "$(inherited)", "-ObjC", "-lz", "-lc++", "-lsqlite3" }) project.AddBuildProperty(frameworkTarget, "OTHER_LDFLAGS", flag); project.SetBuildProperty(frameworkTarget, "CLANG_ENABLE_MODULES", "YES"); project.SetBuildProperty(frameworkTarget, "SWIFT_VERSION", "5.0"); // Swift autolinking locates compatibility archives in the selected Xcode // toolchain for either device or simulator; no hardcoded Xcode paths. foreach (string target in new[] { mainTarget, frameworkTarget }) { project.AddBuildProperty(target, "LIBRARY_SEARCH_PATHS", "$(inherited)"); project.AddBuildProperty(target, "LIBRARY_SEARCH_PATHS", "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\""); project.AddBuildProperty(target, "LIBRARY_SEARCH_PATHS", "\"$(SDKROOT)/usr/lib/swift\""); project.AddBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "$(inherited)"); project.AddBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "/usr/lib/swift"); project.AddBuildProperty(target, "LD_RUNPATH_SEARCH_PATHS", "@executable_path/Frameworks"); } // Apply ARC only to our credentials bridge, preserving other plug-ins. string bridgeGuid = project.FindFileGuidByProjectPath( "Libraries/AppRuntimes/Plugins/iOS/FacebookDynamicCredentials.m"); if (!string.IsNullOrEmpty(bridgeGuid)) { var flags = project.GetCompileFlagsForFile(frameworkTarget, bridgeGuid) ?? new List(); flags.Remove("-fno-objc-arc"); if (!flags.Contains("-fobjc-arc")) flags.Add("-fobjc-arc"); project.SetCompileFlagsForFile(frameworkTarget, bridgeGuid, flags); } } } #endif