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

The project is damaged and cannot be opened due to a parse error.

Discussion in 'iOS and tvOS' started by cmersereau, Mar 29, 2021.

  1. cmersereau

    cmersereau

    Joined:
    Nov 6, 2020
    Posts:
    52
    My team has been using the player identity package for WeChat and have just gotten around to implementing Apple login. The online documentation for setting up Apple login with the player identity package is nonexistent, and once I enabled the Apple Loader for my iOS build and tried building to Xcode, I got the error in the included image. Nothing I found online appears to have anything to do with what I'm experiencing, and trying to read through the .pbxproj file has yielded nothing for me.

    The only other potential noteworthy point is that when I added the ID provider settings and clicked save, they all seem to disappear. I'm not sure if this is actually an issue that the editor isn't saving them properly, or if they are being saved just not displayed for security.

    As soon as I remove the Apple Loader, the build succeeds again.

    Just to recap what created the error:
    1. Set Apple settings and hit save (they seem to disappear, not sure if they persisted)
    2. Added Apple Loader to identity providers
    3. Build and Run (automatically opens Xcode and produces error)
    Screen Shot 2021-03-29 at 4.49.34 PM.png

    Screen Shot 2021-03-29 at 4.55.00 PM.png

    Screen Shot 2021-03-29 at 3.35.16 PM.png


    UPDATE:

    More information. I have been using a diff tool between a working .pbxproj and a broken .pbxproj to try to see where the error might be (not as helpful as it seems, as the contents of the file are not in the same order and generated ids are all different). I found something called Users in the broken version that wasn't in the working version. Searching Users, I stumbled upon this line, which includes some strange characters that seem like they would assuredly create a parse error. When opened in Xcode, these are actually Chinese characters (our game has a Chinese title, although we use an english translation for most things).

    Switching the characters directly in .pbxproj allows me to open the project. This does not solve why this second entitlements file is being created, or what changes need to be made so that I don't have to change this file every build, especially since we utilize cloud build.

    45C04E81B8CC0B4E3820F9C7 /* 生肖行动.entitlements */ = {isa = PBXFileReference; lastKnownFileType = file; name = 生肖行动.entitlements; path = /Users/waysuninc/Desktop/UnityProjects/Lunar/build/iOS/生肖行动.entitlements; sourceTree = SOURCE_ROOT; };
     
    Last edited: Mar 30, 2021
  2. sanercakir

    sanercakir

    Joined:
    Dec 24, 2020
    Posts:
    2
    Struggling with the same problem, did you find a solution?
     
    Last edited: Jun 27, 2021
  3. cmersereau

    cmersereau

    Joined:
    Nov 6, 2020
    Posts:
    52
    Unfortunately I ended up having to wrangle the entitlements into submission. I have a post process method that opens up the entitlements file and literally goes line by line finding and replacing the bad characters. This solution seems far less than ideal, but it works and allows us to use cloud build successfully and not have to manually fix the xcode project every time.

    A couple things worth noting for this snippet, I have replaced the bad characters with {my bad chinese characters} so you can tell how to swap out whatever is bad for you. Also, the naming conventions could possibly be different for you. Lastly, I set the post process order number to 100. All your post process methods will go in an order from lowest to greatest. You will want this to be done after all other methods to make sure that the entitlements doesn't get affected again by some other method. I know that a different method uses a number in the 80's, so I just went to 100.

    Code (CSharp):
    1. [PostProcessBuildAttribute(100)]
    2.     public static void CorrectBadEntitlementsName(BuildTarget buildTarget, string pathToBuiltProject)
    3.     {
    4.         if ( buildTarget != BuildTarget.iOS ) return;
    5.  
    6.         Debug.Log("[IOSProcessingMethods] Fixing incorrectly genereated entitlements file");
    7.  
    8.         // get .pbxproj path name and create temp file for writing corrections
    9.         string pbxPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
    10.         string temp = $"{pathToBuiltProject}/temp.txt";
    11.  
    12.         // go line by line and correct bad text
    13.         using ( var input = File.OpenText(pbxPath) )
    14.         using ( var tempPbx = new StreamWriter(temp) )
    15.         {
    16.             string line;
    17.             while ( null != (line = input.ReadLine()) )
    18.             {
    19.                 line = line.Replace("{my bad chinese characters}", "IGNORE");
    20.                 tempPbx.WriteLine(line);
    21.             }
    22.         }
    23.  
    24.         // Swap the old pbx with the corrected pbx
    25.         File.Delete(pbxPath);
    26.         File.Move(temp, pbxPath);
    27.  
    28.         // Delete the bad entitlements file
    29.         File.Delete($"{pathToBuiltProject}/{my bad chinese characters}.entitlements");
    30.     }
    It's probably also worth noting that for me, I was getting duplicated, unnecessary things added with the bad chinese characters, so I just swapped it for the string "IGNORE". This does not cause these things to be ignored by anything under the hood, it's just a string I choose so that I could search for and identify that my solution was working. You could easily choose whatever other string you want to replace it with. If you need to correct bad characters with a proper fix, then you would add that in place of the "IGNORE" string.
     
    Last edited: Jun 29, 2021