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

Access to .xcodeproj file denied during postbuild

Discussion in 'macOS' started by Numa, Jun 19, 2020.

  1. Numa

    Numa

    Joined:
    Oct 7, 2014
    Posts:
    100
    Hi,

    I'm trying to edit the entitlement file for my OXS standalone build in a post build script.
    I'm getting an access denied exception while trying to read the xcode project file:
    Code (CSharp):
    1.  
    2. [PostProcessBuild(1)]
    3. public static void PostProcess(BuildTarget buildTarget, string buildPath)
    4. {
    5.     var project = new PBXProject();
    6.     project.ReadFromFile(buildPath);
    7. }
    8.  
    9. UnauthorizedAccessException: Access to the path '/Users/me/Builds/MyApp/MyApp.xcodeproj' is denied.
    I tried reading a test .txt file in that same folder and it worked fine, so Unity seems to have the right permissions to that folder.

    Is Unity holding the project file while I'm trying to access it? I use the same code to edit the project on iOS builds and haven't had any issues.

    Edit: I realised the XCode API is actually part of the UnityEditor.iOS namespace so maybe none of this is meant to be used with OSX projects?

    Using Unity 2019.4.1f1 and OSX 10.15.5

    Thanks
     
    Last edited: Jun 19, 2020
  2. bbridgesvb

    bbridgesvb

    Joined:
    Jan 4, 2019
    Posts:
    11
    Hey did you ever find a solution for this? I'm running into the same problem trying to modify my Xcode project for a macOS project in Unity 2020.3.39. Did you get this to work, or did you come up with a work-around for modifying the Xcode project in a PostProcessBuild method?
     
  3. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,602
    Code (CSharp):
    1.  
    2. public static void PostProcess(BuildTarget buildTarget, string buildPath)
    3. {
    4.     var project = new PBXProject();
    5.     project.ReadFromFile(buildPath);
    6. }
    7.  
    this is wrong. buildPath is the folder where things are put
    you need something like

    Code (CSharp):
    1. string projPath = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
    2.  
    3. PBXProject proj = new PBXProject();
    4. proj.ReadFromString(File.ReadAllText(projPath));
     
  4. bbridgesvb

    bbridgesvb

    Joined:
    Jan 4, 2019
    Posts:
    11
    Thanks @Alexey, that did the trick!