ArdaZeytin
ArdaZeytin

Reputation: 1324

Script changing 'Run script only when installing' flag of Run Script phase of Xcode

I want to change 'Run script only when installing' flag from false to true when every time I build xCode project from Unity Editor. Expected result should be like in screenshot. enter image description here

Here is my code that adds shell script to build phase when I build xCode project. It should run only after Archive process to delete some files from archived file. Unity documentation related to my script -> https://docs.unity3d.com/2020.2/Documentation/ScriptReference/iOS.Xcode.PBXProject.html

using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using UnityEngine;

namespace VP.Nest.System.Editor
{
    public static class DeleteFrameworkIOS
    {
        [PostProcessBuild(1000)]
        public static void OnPostProcessBuild(BuildTarget target, string pathToBuildProject)
        {
            if (target == BuildTarget.iOS)
            {
                var projectPath = PBXProject.GetPBXProjectPath(pathToBuildProject);

                var pbxProject = new PBXProject();
                pbxProject.ReadFromFile(projectPath);

#if UNITY_2019_3_OR_NEWER
                var targetGuid = pbxProject.GetUnityMainTargetGuid();
#else
            var targetName = PBXProject.GetUnityTargetName();
            var targetGuid = pbxProject.TargetGuidByName(targetName);
#endif
                string shellScriptPath = Path.GetDirectoryName(Application.dataPath) + "/Assets/VirtualProjects/Games/Scripts/Editor/BuildAutomation/DeleteFrameworkXCode.sh";

                pbxProject.AddShellScriptBuildPhase(targetGuid,"Run Script DeleteFrameworkXCode.sh", "/bin/sh", shellScriptPath);
                //TODO: Set 'Run script only when installing' flag to true
                pbxProject.WriteToFile(projectPath);
            }
        }
    }
}

How can I set this "For Install builds only" flag to true from my script? I should be able to do something like this -> https://gist.github.com/rizumita/4240658a9c999460ec4777ba5825f791

Upvotes: 0

Views: 1444

Answers (1)

袁宇昊
袁宇昊

Reputation: 1

I meet the same question and I resolve it by inserting codes in podfile like this:

phase = target.shell_script_build_phases.find { |bp| ignoringScriptNames.include?(your_phase_name) }
phase.run_only_for_deployment_postprocessing = "1"

This may help you.

Upvotes: 0

Related Questions