Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A workaround for missing header file in Unity iOS builds with the Facebook SDK
// workaround for missing header file bug
// remove when FB SDK patched (tracker:
#if UNITY_2019_3_OR_NEWER
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
namespace AeLa.Editor
internal static class FBSDKWorkaround
private static void OnPostProcessBuild(BuildTarget target, string buildPath)
if (target != BuildTarget.iOS) return;
// add missing file
var fullPath = Path.Combine(buildPath, "Libraries", "RegisterMonoModules.h");
if (!File.Exists(fullPath))
Log($"Creating file {fullPath}");
Log($"Adding file to xcode project...");
AddFileToXCodeProj(buildPath, fullPath);
Log($"Found file at {fullPath}, not overwriting");
private static void AddFileToXCodeProj(string buildPath, string filePath)
// load pbx project
var pbxPath = Path.Combine(buildPath, "Unity-iPhone.xcodeproj", "project.pbxproj");
var project = new UnityEditor.iOS.Xcode.PBXProject();
// add file
var target = project.GetUnityMainTargetGuid();
targetGuid: target,
sectionGuid: project.AddSourcesBuildPhase(target),
fileGuid: project.AddFile(filePath, filePath)
// write pbx project changes
File.WriteAllText(pbxPath, project.WriteToString());
private static void Log(string message, LogType type = LogType.Log)
Debug.unityLogger.Log(type, $"[FB SDK Workaround] {message}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment