When we build our Unity project for iOS, it generates an Xcode project which uses Cocoapods. I’m trying to make a build post-process script (C#, running in the Unity Editor) that edits the Podfile and then runs pod install
in the build directory.
I’ve tried several different approaches to run pod install
which all fail in one of two ways:
private static void ExecuteProcess(string directory, string argument) {
try {
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo() {
FileName = "/bin/bash",
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
CreateNoWindow = true,
WorkingDirectory = directory,
Arguments = " -c "" + argument + " ""
};
System.Diagnostics.Process myProcess = new System.Diagnostics.Process {
StartInfo = startInfo
};
myProcess.Start();
while (!myProcess.StandardOutput.EndOfStream) {
var line = myProcess.StandardOutput.ReadLine();
UnityEngine.Debug.Log(line);
}
} catch (System.Exception e) {
UnityEngine.Debug.Log(e);
}
}
private static void TryInstallPods() {
const string BUILDS_PATH = "./Builds";
string shellScriptPath = Path.Join(BUILDS_PATH, "podinstall.sh");
// Outputs nothing
File.WriteAllText(shellScriptPath, "pod install --verbose");
ExecuteProcess(BUILDS_PATH, "sh podinstall.sh");
// Outputs "CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only performed in repo update"
File.WriteAllText(shellScriptPath, "/usr/local/bin/pod install --verbose");
ExecuteProcess(BUILDS_PATH, "sh podinstall.sh");
// Outputs nothing
ExecuteProcess(BUILDS_PATH, "pod install --verbose");
// Outputs "CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only performed in repo update"
ExecuteProcess(BUILDS_PATH, "/usr/local/bin/pod install --verbose");
// For reference, this works as expected for the build directory:
ExecuteProcess(BUILDS_PATH, "ls");
// This also works as expected:
ExecuteProcess(BUILDS_PATH, "/usr/local/bin/pod --help");
// This produces no output:
ExecuteProcess(BUILDS_PATH, "pod --help");
}
Note that this shell script is generated by the code:
podinstall.sh
/usr/local/bin/pod install --verbose
- From my C# code,
pod install --verbose
produces no output, whether it’s called directly or from inside a shell script. - From my C# code,
"/usr/local/bin/pod install --verbose"
produces the output “CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only performed in repo update”, whether it’s called directly or from inside a shell script. Nothing else happens and the pod configuration isn’t updated.
I get the same results if I try the approach described here: https://forum.unity.com/threads/adjusting-pods-pods-xcproject-after-pod-install.1406500/
However, any variation works if I open a terminal window in the build folder and type the command there:
% pod install --verbose
% /usr/local/bin/pod install --verbose
% sh podinstall.sh
Why do these commands work if I type them into the terminal window, but not when I try to run them from a process in C#/Unity?
Note: I have reformatted the code for this question; this question might contain typos that are not present in the original code.