Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Run application on Xcode Build Phases

Discussion in 'Unity Cloud Build' started by Kujo87, Dec 17, 2020.

  1. Kujo87


    Sep 16, 2013

    Our games use Fyber Fairbid for ad mediation and they have recently updated their SDK to work with SKAD requirements for iOS 14. As part of their toolkit to add to this, they have a post build script that is part of Xcode that runs a small C++ program that basically checks your pod file for networks that you've added and pulls in the required SKAD Adapters into your plist. Its fairly simple but requires the application be part of your path.

    Obviously I understand thats not something you're going to add to Cloud for the odd person that uses it, but I was wondering how we could achieve this. I tried including their C++ application into my Unity project and using its full path for it, but when it comes to run it, it errors with Permission denied. Is it possible to run an application on Cloud build to do this, or is it something completely blocked? If I can do it, how can it be done?

    I've been working closely with their team on this, but their knowledge of Cloud build is limited and so far, we haven't found a solution that works.

    I've included links to their documentation for their skad_updater (the program that needs running), as well as the post build method that adds the build phase script into Xcode.

    Code (csharp):
    2. using UnityEditor;
    3. using UnityEditor.iOS.Xcode;
    4. using UnityEditor.Callbacks;
    6. public static class SKAdNetworkUpdater
    7. {
    8.     [PostProcessBuild(1)]
    9.     public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    10.     {
    11.         if (buildTarget != BuildTarget.iOS)
    12.         {
    13.             return;
    14.         }
    16.         string projectPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
    17.         PBXProject pbxProject = new PBXProject();
    18.         pbxProject.ReadFromFile(projectPath);
    20. #if UNITY_2019_3_OR_NEWER
    21.         string targetGUID = pbxProject.GetUnityMainTargetGuid();
    22. #else
    23.         string targetGUID = pbxProject.TargetGuidByName("Unity-iPhone");
    24. #endif
    26.         string shellPath = "/bin/sh";
    27.         int index = 0;
    28.         string name = "Update SKAdNetwork ids";
    29.         string shellScript = @"echo ""$INFOPLIST_FILE"" | sed 's/ /\\ /g' | (read SANITIZED_PATH; skad_updater --plist_file_path ""$SANITIZED_PATH"" --network_list=FairBidSDK --pod_file_path ./Podfile; plutil -convert xml1 ""$SANITIZED_PATH"")";
    30.         pbxProject.InsertShellScriptBuildPhase(index, targetGUID, name, shellPath, shellScript);
    31.         pbxProject.WriteToFile(projectPath);
    32.     }
    33. }