In Unity, because of the packages i use in project i need to run pod commands after build. Doing it every time takes so much time. I want to run pod commands after build automatically. I use the code below to run pod commands but it says Run command not found. I tried $ instead of run but it didn’t work. How can i run these commands ?
#if UNITY_EDITOR && UNITY_IOS
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Callbacks;
using System.Diagnostics;
using System.IO;
public class XcodePostProcess
{
[PostProcessBuild]
static void OnPostProcessGenPodfile(BuildTarget buildTarget, string pathToBuiltProject)
{
if (buildTarget != BuildTarget.iOS)
return;
// update the Xcode project file
var projPath = Path.Combine(pathToBuiltProject, "Unity-iPhone.xcodeproj/project.pbxproj");
var project = new UnityEditor.iOS.Xcode.PBXProject();
project.ReadFromFile(projPath);
// Get the Podfile and copy it into the Xcode project folder
var target = project.GetUnityFrameworkTargetGuid();
File.Copy("Assets/Editor/MyPodfile", Path.Combine(pathToBuiltProject, "Podfile"), true);
project.AddBuildProperty(target, "CLANG_ENABLE_MODULES", "YES");
File.WriteAllText(projPath, project.WriteToString());
List<Process> processes = new List<Process>()
{
new Process()
{
StartInfo =
{
WorkingDirectory = pathToBuiltProject,
FileName = "/usr/local/bin/pod",
Arguments = "Run rm -rf ~/Library/Developer/Xcode/DerivedData",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
},
},
new Process()
{
StartInfo =
{
WorkingDirectory = pathToBuiltProject,
FileName = "/usr/local/bin/pod",
Arguments = "Run pod deintegrate",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
},
}, new Process()
{
StartInfo =
{
WorkingDirectory = pathToBuiltProject,
FileName = "/usr/local/bin/pod",
Arguments = "Run pod cache clean --all",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
},
}, new Process()
{
StartInfo =
{
WorkingDirectory = pathToBuiltProject,
FileName = "/usr/local/bin/pod",
Arguments = "Run pod repo update",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
},
}, new Process()
{
StartInfo =
{
WorkingDirectory = pathToBuiltProject,
FileName = "/usr/local/bin/pod",
Arguments = "Run pod install",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
},
}, new Process()
{
StartInfo =
{
WorkingDirectory = pathToBuiltProject,
FileName = "/usr/local/bin/pod",
Arguments = "Run pod update",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
},
}
};
try
{
for (int i = 0; i < processes.Count; i++)
{
processes[i].Start();
while (!processes[i].StandardOutput.EndOfStream)
{
var line = processes[i].StandardOutput.ReadLine();
UnityEngine.Debug.Log(line);
}
UnityEngine.Debug.Log($"{processes[i].StartInfo.Arguments} completed");
}
}
catch (System.Exception ex)
{
UnityEngine.Debug.LogError(ex.StackTrace);
}
}
}
#endif