Unable to open project... cannot be opened because the project file cannot be parsed

IphoneXcode

Iphone Problem Overview


I have been working for a while to create an iPhone app. Today when my battery was low, I was working and constantly saving my source files then the power went out...

Now when I plugged my computer back in and it is getting good power I try to open my project file and I get an error:

>Unable to Open Project > >Project ... cannot be opened because the project file cannot be parsed.

Is there a way that people know of that I can recover from this? I tried using an older project file and re inserting it and then compiling. It gives me a funky error which is probably because it isn't finding all the files it wants...

I really don't want to rebuild my project from scratch if possible.


EDIT

Ok, I did a diff between this and a slightly older project file that worked and saw that there was some corruption in the file. After merging them (the good and newest parts) it is now working.

Great points about the SVN. I have one, but there has been some funkiness trying to sync XCode with it. I'll definitely spend more time with it now... ;-)

enter image description here

Iphone Solutions


Solution 1 - Iphone

I came across this problem and my senior told me about a solution i.e:

Right click on your projectname.xcodeproj file here projectname will be the name of your project. Now after right clicked select Show Packages Contents. After that open your projectname.pbxproj file in a text editor. Now search for the line containing <<<<<<< .mine, ======= and >>>>>>> .r. For example in my case it looked liked this

<<<<<<< .mine
    9ADAAC6A15DCEF6A0019ACA8 .... in Resources */,
=======
    52FD7F3D15DCEAEF009E9322 ... in Resources */,
>>>>>>> .r269

Now remove those <<<<<<< .mine, ======= and >>>>>>> .r lines so it would look like this

    9ADAAC6A15DCEF6A0019ACA8 /* BuyPriceBtn.png in Resources */,

    52FD7F3D15DCEAEF009E9322 /* discussionForm.zip in Resources */,

Now save and open your Xcode project and build it. Everything will be fine.

Solution 2 - Iphone

Muhammad's answer was very helpful (and helped lead to my fix). However, simply removing the >>>>>>> ======= <<<<<<< wasn't enough to fix the parse issue in the project.pbxproj (for me) when keeping changes from both branches after a merge.

I had a merge conflict in the PBXGroup section (whose beginning is indicated by a block comment like this: /* Begin PBXGroup section */) of the project.pbxproj file. However, the problem I encountered can occur in other places in the project.pbxproj file as well.

Below is a simplification of the merge conflict I encountered:

    <<<<<<< HEAD
          id = {
            isa = PBXGroup;
            children = (
                 id
            );
            name = "Your Group Name";
    =======
          id = {
            isa = PBXGroup;
            children = (
                 id
            );
            name = "Your Group Name";
    >>>>>>> branch name
            sourceTree = "<group>";
          };
           

When i removed the merge conflict markers this is what I was left with:

          id = {
            isa = PBXGroup;
            children = (
                 id
            );
            name = "Your Group Name";
          id = {
            isa = PBXGroup;
            children = (
                 id
            );
            name = "Your Group Name";
            sourceTree = "<group>";
          };

Normally, removing the merge conflict markers would fix the parse issue in the project.pbxproj file and restore the workspace integrity. This time it didn't.

Below is what I did to solve the issue:

          id = {
            isa = PBXGroup;
            children = (
                 id
            );
            name = "Your Group Name";
            sourceTree = "<group>";
          };

          id = {
            isa = PBXGroup;
            children = (
                 id
            );
            name = "Your Group Name";
            sourceTree = "<group>";
          };

I actually had to add 2 lines at the end of the first PBXGroup.

You can see that if I would have chosen to discard the changes from either Head or the merging branch, there wouldn't have been a parse issue! However, in my case I wanted to keep both groups I added from each branch and simply removing the merge markers wasn't enough; I had to add extra lines to the project.pbxproj file in order to maintain correct formatting.

So, if you're running into parsing issues after you thought you'd resolved all you're merge conflicts, you might want to take a closer look at the .pbxproj and make sure there aren't any formatting problems!

Solution 3 - Iphone

I got this exact same error because Cordova will allow you to create a project with spaces in it, and Xcode doesn't know how to deal.

Solution 4 - Iphone

I had similar issue.

Screenshot 1

Below are steps to resolve it:

  1. Navigate to folder where your projectName.xcodeproj.

Screenshot 2

  1. Right click and select 'Show Package Contents'. You will be able to see list of files with .pbxproj extension.

Screenshot 3

  1. Select project.pbxproj. Right click and open this file using 'Text Edit'.

Screenshot 4

  1. You will be able to see <<<<<< .mine , ============ and >>>>>>>>>> .r123. These are generally conflicts that arise when you take update from SVN. Delete these and save file.

Screenshot 5

Screenshot 6

  1. Now, you'll be able to open project without any error message.

Solution 5 - Iphone

Visual analysis of the Xcode project file did not help me to locate error after merging. After looking to syslog found such line when Xcode trying to parse the file:

2/7/14 12:39:12.792 PM Xcode[9949]: CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary on line 4426. Parsing will be abandoned. Break on _CFPropertyListMissingSemicolon to debug.

After fixing that project can be opened ok.

Solution 6 - Iphone

Analyse the syntax of your project file. Check it inside your project in terminal:

plutil -lint project.pbxproj

This will show you the errors from the parser.

Possible problem: Some projects set git merging strategy union for project files. This works for most of the times, but will silently kill your project file if it fails. This strategy is defined in the .gitattributes file in your repository.

Solution 7 - Iphone

I faced the same problem recently when trying to merge my branch with a remote branch. However, none of the above solutions seemed appropriate to my problem.

There were no merge conflicts between the project.pbxproj file in my branch or the remote branch. However, my projectName.xcodeproj file would refuse to open for the same reason as shown in the asked question.

My solution was to look through the project.pbxproj using a text editor and find if there were any irregularities in the file syntax (for e.g. an extra curly bracket). I sped this process up by focusing on the lines which were inserted or deleted in old file as compared to the merged file. On closer examination, I found the cause of my problem was the repetition of the following line :

xxxxxxxxxxxxx /* [CP] Check Pods Manifest.lock */ = {

in my merged file. This led to an unclosed curly bracket and consequent invalid pbxproj syntax. Deleting the above line fixed my problem.

Solution 8 - Iphone

Steps to be followed:- 1.Navigate to folder where your projectName.xcodeproj 2.Right click and select 'Show Package Contents'. You will be able to see list of files with .pbxproj extension. 3.Select project.pbxproj. Right click and open this file using 'Text Edit'. 4.You will be able to see <<<<<<, ============ and >>>>>>>>>>. These are generally conflicts that arise when you take update from Sourcetree/SVN/GITLAB. Delete these and save file. 5.Now, you'll be able to open project without any error message.

Solution 9 - Iphone

I just ran into same problem. I removed generated strings by git as always but Xcode still refused to open .xcodeproj file. But everything was correct, no missing brackets etc. Finally I tried to quit Xcode and open project when Xcode was closed.. then it worked. I hope this helps someone.

EDIT:

for resolving conflicts in your .xcodeproj file you can use this handy script:

  1. Create empty .sh file in your project directory ( e.g. resolve_conflicts.sh )

  2. Here is the script:

    projectfile=find -d . -name 'project.pbxproj' projectdir=echo *.xcodeproj projectfile="${projectdir}/project.pbxproj" tempfile="${projectdir}/project.pbxproj.out" savefile="${projectdir}/project.pbxproj.mergesave"

    cat $projectfile | grep -v "<<<<<<< HEAD" | grep -v "=======" | grep -v "^>>>>>>> " > $tempfile mv $tempfile $projectfile

  3. Run it from terminal using sh command: sh resolve_conflicts.sh

Solution 10 - Iphone

Revert the project.pbxproj

svn revert --filename--

Solution 11 - Iphone

It sounds like you're going to have to create a new project in Xcode, go into the old directory, and drag all your source files, nibs, and resources into the Xcode files sidebar in the new project. It shouldn't take more than a few minutes, unless you really did a lot of work with custom build settings or targets. Either that, or revert to the last check-in in your source control and manually add any code files which changed between now and then.

Solution 12 - Iphone

And once you get things working again you should look into using something like subversion or mercurial for backup and revision control. Remember that he electrons don't always go where they are supposed to, backup early and often!

Solution 13 - Iphone

change your current project folder nam and checkout module the same project.then add the current file changes.

Solution 14 - Iphone

Just check the project.pbproject file and do a diff against a working version of the project file.

Often times this happens when you have conflicts from a version control system like posted here: https://stackoverflow.com/questions/1496182/user-file-cannot-be-parsed-in-subversion-in-mac-iphone-sdk

Solution 15 - Iphone

Try to find HEAD and _HEAD between the lines and delete this words in project.pbxproj. Backup this file before doing this..

Solution 16 - Iphone

Goto PhoneGapTest>>platform Then delete the folder ios after that go to terminal then type: sudo phonegap build ios after that you can run the project

Solution 17 - Iphone

By reverting, you can undo pulled code.

If you want to undo that pull request just put this command on project path

--> git merge --abort

Solution 18 - Iphone

In case if you did not find in Text === or <<< or >>>> like was for me problem was really simple and fun... I change name of App in Xcode, but not change it in UnityProjectSettings before build - that was the problem...

Solution 19 - Iphone

If you ever merge and still get problems that dont know what they are, I mean not the obvious marks of a diff

<<<<<
....
======
>>>>>>

Then you can analise your project files with https://github.com/Karumi/Kin, install it and use it

kin project.pbxproj

It has make extrange erros that doesn't allow open the project more easy to understand and solve (ones of hashes, groups and so on).


And by the way, this could also be helpful, thought I have not used it try to diff 2 versions of your project files https://github.com/bloomberg/xcdiff so this will give you really what is going on.

Solution 20 - Iphone

In my experience, I needed a combination of tactics for this:

A-

1-Use git merge from the command line to figure out what files need to be resolved

2-Use git add or git rm as appropriate with those files

3-Use git commit to finish the merger

B- 1-for the .pbxproj I removed the <<<< , >>>> and the =====

2- used https://github.com/Serchinastico/Kin to find merging errors, and using SnoopyProtocol's answer I fixed those issues

Note: at one point the only error Kin was showing was: ERROR: line 1197:40 mismatched input '1' expecting NON_QUOTED_STRING which didn't need to be fixed for the Xcode project to be openable

Solution 21 - Iphone

subversion will corrupt my project file after a svn up on an almost weekly basis. I'm trying to figure out why it does this right now and came across this problem.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChris ButlerView Question on Stackoverflow
Solution 1 - IphoneUsufView Answer on Stackoverflow
Solution 2 - IphoneSnoopyProtocolView Answer on Stackoverflow
Solution 3 - IphonebwagsView Answer on Stackoverflow
Solution 4 - IphoneJayprakash DubeyView Answer on Stackoverflow
Solution 5 - IphoneOleksiy IvanovView Answer on Stackoverflow
Solution 6 - IphonebesederView Answer on Stackoverflow
Solution 7 - IphoneAbhiView Answer on Stackoverflow
Solution 8 - IphoneAkash SinghView Answer on Stackoverflow
Solution 9 - IphoneVojtaView Answer on Stackoverflow
Solution 10 - IphonemondousageView Answer on Stackoverflow
Solution 11 - IphoneMarc CharbonneauView Answer on Stackoverflow
Solution 12 - IphoneBrian C. LaneView Answer on Stackoverflow
Solution 13 - IphonesureshView Answer on Stackoverflow
Solution 14 - IphoneAtmaView Answer on Stackoverflow
Solution 15 - IphoneAvi Shim.View Answer on Stackoverflow
Solution 16 - IphoneRanchView Answer on Stackoverflow
Solution 17 - IphoneSubramaniView Answer on Stackoverflow
Solution 18 - IphoneAnton KonoplianchenkoView Answer on Stackoverflow
Solution 19 - Iphonetyoc213View Answer on Stackoverflow
Solution 20 - IphoneMostafa ElShazlyView Answer on Stackoverflow
Solution 21 - IphoneStrobedreamView Answer on Stackoverflow