Skip to content

Instantly share code, notes, and snippets.

@ntratcliff
Created June 11, 2020 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntratcliff/3942abd1eed9d704713a27616f09628b to your computer and use it in GitHub Desktop.
Save ntratcliff/3942abd1eed9d704713a27616f09628b to your computer and use it in GitHub Desktop.
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