Unity IOS PostProcessBuild

问题描述 投票:0回答:1

在 Unity 中,由于我在项目中使用的软件包,我需要在构建后运行 pod 命令。每次做这件事都需要花费很多时间。我想在构建后自动运行 pod 命令。我使用下面的代码来运行 pod 命令,但它说未找到运行命令。我尝试使用 $ 而不是 run 但它不起作用。我如何运行这些命令?

#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
ios unity-game-engine build
1个回答
0
投票

尝试从参数中删除“Run pod”。您已经指定希望通过 Filename 参数使用 pod 命令,因此请在 StartInfo 参数中尝试类似的操作:

FileName = "/usr/local/bin/pod",
Arguments = "update"
© www.soinside.com 2019 - 2024. All rights reserved.