#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) { const string sdkRelativePath = "ThirdParty/FacebookSDK/Plugins/iOS/XCFrameworks"; string sdkRoot = AppHelpPackagePaths.FullPath(sdkRelativePath); string[] modules = { "FBAEMKit", "FBSDKCoreKit_Basics", "FBSDKCoreKit", "FBSDKLoginKit", "FBSDKShareKit", "FBSDKGamingServicesKit" }; foreach (string module in modules) { string assetPath = AppHelpPackagePaths.AssetPath(sdkRelativePath + "/" + 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); string xcframework = Path.Combine(sdkRoot, module + ".xcframework"); if (!File.Exists(Path.Combine(xcframework, "Info.plist"))) throw new BuildFailedException("Missing local Facebook XCFramework: " + xcframework); 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"); 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"); } foreach (string sourcePath in project.GetRealPathsOfAllFiles(PBXSourceTree.Source)) { if (Path.GetFileName(sourcePath) != "FacebookDynamicCredentials.m") continue; string bridgeGuid = project.FindFileGuidByRealPath(sourcePath, PBXSourceTree.Source); 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