Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Adjusting Pods/Pods.xcproject after pod install

Discussion in 'Unity Build Automation' started by ramonvitor, Mar 1, 2023.

  1. ramonvitor

    ramonvitor

    Joined:
    Feb 17, 2023
    Posts:
    2
    Hello!

    I need to make some modifications to the PBX project that exists within the Pods.xcproject after the `pod install` is run so that I can enable Bitcode in the Pods project. I wanted to try one of either:
    - Run an equivalent to the PostProcessBuild AFTER the `pod install`
    - Run the `pod install` during a PostProcessBuild step

    The first one, I have no idea how to accomplish. Is there any doc for that?

    Regarding the second one, I need to know where is the cocoapod binary, so that I can call using a Process in the PostProcessBuild step. Do you guys have a doc specifying where is this binary located? For instance, on my machine, it is located at `/opt/homebrew/bin/pod`.

    Looking forward to hearing from you

    Best,
    Ramon
     
  2. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,077
    I've worked on a few projects where we actually just run the 'pod install' ourselves so maybe that would work for you? You could put your own post processing code after that.

    Code (CSharp):
    1.     public static class PostProcessor
    2.     {
    3.         [PostProcessBuild]
    4.         static void OnPostProcessGenPodfile(BuildTarget buildTarget, string pathToBuiltProject)
    5.         {
    6.             if (buildTarget != BuildTarget.iOS)
    7.                 return;
    8.  
    9.             // update the Xcode project file
    10.             var projPath = Path.Combine(pathToBuiltProject, "Unity-iPhone.xcodeproj/project.pbxproj");
    11.             var project = new UnityEditor.iOS.Xcode.PBXProject();
    12.             project.ReadFromFile(projPath);
    13.  
    14.             // Get the Podfile and copy it into the Xcode project folder
    15.             var target = project.GetUnityFrameworkTargetGuid();
    16.             File.Copy("Assets/Editor/MyPodfile", Path.Combine(pathToBuiltProject, "Podfile"), true);
    17.  
    18.             project.AddBuildProperty(target, "CLANG_ENABLE_MODULES", "YES");
    19.             File.WriteAllText(projPath, project.WriteToString());
    20.  
    21.             var proc = new Process
    22.             {
    23.                 StartInfo =
    24.                 {
    25.                     WorkingDirectory = pathToBuiltProject,
    26.                     #if UNITY_CLOUD_BUILD
    27.                     FileName = "pod",
    28.                     #else
    29.                     FileName = "/usr/local/bin/pod",
    30.                     #endif
    31.                     Arguments = "install --repo-update",
    32.                     UseShellExecute = false,
    33.                     RedirectStandardOutput = true,
    34.                     CreateNoWindow = true
    35.                 }
    36.             };
    37.             proc.Start();
    38.             while (!proc.StandardOutput.EndOfStream)
    39.             {
    40.                 var line = proc.StandardOutput.ReadLine();
    41.                 Debug.Log(line);
    42.             }
    43.         }
    44.     }
    45.  
    Note: The cloud build uses some type of virtual machine so the directory path for the 'pod' exe is different.
     
    ramonvitor likes this.
  3. ramonvitor

    ramonvitor

    Joined:
    Feb 17, 2023
    Posts:
    2
    This worked like a charm. For future reference, the location of the `pod` binary can be found by running `which pod` inside the Unity Cloud build. It was on some weird path but worked.

    We ended up going with another solution in the end, which was just configuring the Podfile inside the Podfile:

    Code (csharp):
    1.  
    2. source 'https://github.com/CocoaPods/Specs.git'
    3.  
    4. ...
    5.  
    6. post_install do |installer|
    7.    installer.pods_project.targets.each do |target|
    8.       target.build_configurations.each do |config|
    9.          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
    10.             config.build_settings['ENABLE_BITCODE'] = 'YES' # Added this line to configure the BITCODE
    11.       end
    12.    end
    13. end
    14.  
     
    roointan and tonemcbride like this.
  4. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,077
    That's a nice solution, I didn't realise you could modify those settings within the podfile so that's good to know.