Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A workaround for missing header file in Unity iOS builds with the Facebook SDK https://github.com/facebook/facebook-sdk-for-unity/issues/359
// workaround for missing header file bug
// remove when FB SDK patched (tracker: https://github.com/facebook/facebook-sdk-for-unity/issues/359)
#if UNITY_2019_3_OR_NEWER
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
namespace AeLa.Editor
{
internal static class FBSDKWorkaround
{
[PostProcessBuild(99)]
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}");
File.Create(fullPath).Close();
Log($"Adding file to xcode project...");
AddFileToXCodeProj(buildPath, fullPath);
}
else
{
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();
project.ReadFromString(File.ReadAllText(pbxPath));
// add file
var target = project.GetUnityMainTargetGuid();
project.AddFileToBuildSection(
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}");
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment