public static void OnPostProcessUpdateProjectDeps(
BuildTarget buildTarget, string pathToBuiltProject) {
if (!InjectDependencies()) return;
// If the Pods directory does not exist, the pod download step
// failed.
var podsDir = Path.Combine(pathToBuiltProject, "Pods");
if (!Directory.Exists(podsDir)) return;
Directory.CreateDirectory(Path.Combine(pathToBuiltProject,
"Frameworks"));
Directory.CreateDirectory(Path.Combine(pathToBuiltProject,
"Resources"));
string pbxprojPath = GetProjectPath(pathToBuiltProject);
var project = new UnityEditor.iOS.Xcode.PBXProject();
project.ReadFromString(File.ReadAllText(pbxprojPath));
string target = project.TargetGuidByName(TARGET_NAME);
HashSet<string> frameworks = new HashSet<string>();
HashSet<string> linkFlags = new HashSet<string>();
foreach (var frameworkFullPath in
Directory.GetDirectories(podsDir, "*.framework",
SearchOption.AllDirectories)) {
string frameworkName = new DirectoryInfo(frameworkFullPath).Name;
string destFrameworkPath = Path.Combine("Frameworks",
frameworkName);
string destFrameworkFullPath = Path.Combine(pathToBuiltProject,
destFrameworkPath);
// Only move this framework if it contains a library.
// Skip frameworks that consist of just resources, they're handled
// in a separate import step.
if (!File.Exists(Path.Combine(
frameworkFullPath,
Path.GetFileName(frameworkFullPath)
.Replace(".framework", "")))) {
continue;
}
PlayServicesSupport.DeleteExistingFileOrDirectory(
destFrameworkFullPath);
Directory.Move(frameworkFullPath, destFrameworkFullPath);
project.AddFileToBuild(
target,
project.AddFile(destFrameworkPath,
destFrameworkPath,
UnityEditor.iOS.Xcode.PBXSourceTree.Source));
string moduleMapPath =
Path.Combine(Path.Combine(destFrameworkFullPath, "Modules"),
"module.modulemap");
if (File.Exists(moduleMapPath)) {
// Parse the modulemap, format spec here:
// http://clang.llvm.org/docs/Modules.html#module-map-language
using (StreamReader moduleMapFile =
new StreamReader(moduleMapPath)) {
string line;
char[] delim = {' '};
while ((line = moduleMapFile.ReadLine()) != null) {
string[] items = line.TrimStart(delim).Split(delim, 2);
if (items.Length > 1) {
if (items[0] == "link") {
if (items[1].StartsWith("framework")) {
items = items[1].Split(delim, 2);
frameworks.Add(items[1].Trim(
new char[] {'\"'}) + ".framework");
} else {
linkFlags.Add("-l" + items[1]);
}
}
}
}
}
}
string resourcesFolder = Path.Combine(destFrameworkFullPath,
"Resources");
if (Directory.Exists(resourcesFolder)) {
string[] resFiles = Directory.GetFiles(resourcesFolder);
string[] resFolders =
Directory.GetDirectories(resourcesFolder);
foreach (var resFile in resFiles) {
string destFile = Path.Combine("Resources",
Path.GetFileName(resFile));
File.Copy(resFile, Path.Combine(pathToBuiltProject,
destFile), true);
project.AddFileToBuild(
target, project.AddFile(
destFile, destFile,
UnityEditor.iOS.Xcode.PBXSourceTree.Source));
}
foreach (var resFolder in resFolders) {
string destFolder =
Path.Combine("Resources",
new DirectoryInfo(resFolder).Name);
string destFolderFullPath =
Path.Combine(pathToBuiltProject, destFolder);
PlayServicesSupport.DeleteExistingFileOrDirectory(
destFolderFullPath);
Directory.Move(resFolder, destFolderFullPath);
project.AddFileToBuild(
target, project.AddFile(
destFolder, destFolder,
UnityEditor.iOS.Xcode.PBXSourceTree.Source));
}
}
}
foreach (var framework in frameworks) {
project.AddFrameworkToProject(target, framework, false);
}
foreach (var linkFlag in linkFlags) {
project.AddBuildProperty(target, "OTHER_LDFLAGS", linkFlag);
}
File.WriteAllText(pbxprojPath, project.WriteToString());
}
}