106

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

Community
  • 1
  • 1

21 Answers21

241

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.

Simon
  • 31,675
  • 9
  • 80
  • 92
Usuf
  • 2,569
  • 1
  • 13
  • 10
  • 11
    THANK YOU. This works. In my case it wasn't ".mine" or ".r" but said something else... Ctrl-F for "===" to find the place. – ck_ Oct 31 '12 at 17:22
  • this should be marked as the answer. Really good stuff, thanks – owen gerig May 10 '13 at 15:10
  • 13
    Just to say WHY this is happening: Your version control is trying to merge two conflicting versions of the project file. You must manually tell your version control what the proper merge is. The fact that XCode doesn't handle this gracefully is a huge annoyance to me on a daily basis. – Thane Brimhall May 22 '13 at 20:33
  • Thank you. My issue came in the form of <<<<<<<<< HEAD ======= >>>>>>>. It was in two spots towards the end of .pbxproj file. Once I removed these items I was able to execute the .xcodeproj file again. Look for these items to be visibly out of place from the rest of the file. – AgnosticDev Jun 23 '14 at 12:43
  • This was such a lifesaver. I thought I totally messed up the whole project. Thank you! – Zack Shapiro Feb 08 '15 at 20:11
  • Just so show my gratitude for this simple fix. Had major issues with merging two branches. Thank you!! – Robert J. Clegg Jun 19 '15 at 11:56
  • 1
    In my case its <<<<<<< HEAD, ======, >>>>>>> some alphanumeric. Remove these three lines then save and open. Worked Like a Charm!!! Thanks Allot. – Gowrie Sammandhamoorthy Oct 17 '16 at 20:07
  • Thank the good lord for this answer. Saved me a beating from my team. – Chad Lewis Apr 25 '17 at 05:52
  • All hail @Usuf, whose answer is still relevant years later! – Rethunk Jan 14 '21 at 20:09
54

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!

SnoopyProtocol
  • 911
  • 8
  • 10
  • you probably accidentally removed the colon and/or curly brace when resolving merge conflicts. You should carefully take the proper part (or both) from the merge conflicts and remove markers. That's it. – Stas Apr 27 '16 at 12:15
  • adding the sourceTree = ""; }; resolved it for me! So helpful! Thanks! – Nitin Alabur Jun 20 '16 at 18:32
  • Just wanted to add something to this. I had this same problem but working with CocoaPods and a workspace. I had to nuke the workspace and re-create it in order for Xcode to pick up the fix. – Nico Jun 12 '17 at 19:28
  • @Nico: Do you mind to share on how to nuke it? I'm facing the similar issue here and having a hard time – Isaac Dec 21 '18 at 07:57
  • I found that after fixing the .pbxproj file that I needed to close and reopen the project to get it to work, but it did work. Thanks SnoopyProtocol! – KeithTheBiped Apr 23 '19 at 14:32
  • God bless you brother! – MihaiL Aug 13 '20 at 08:36
  • Thank you, that was exactly my problem. I accepted both changes and somehow a curly brace and semicolon was not added. – devno Aug 04 '21 at 07:52
28

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.

bwags
  • 998
  • 9
  • 16
  • Thanks a lot this was the answer, i had a space. – Max Jul 18 '13 at 14:26
  • Same with Cordova Phonegap 3.4 – Miles M. Jul 01 '14 at 07:42
  • This was exactly the issue I was having. Thanks! – fray88 Sep 29 '15 at 09:58
  • @fray88 I took out the space in my folder name for both the Xcode project and the cordova folder, but now I am getting a Error: ENOENT: no such file or directory error. How can I take out the space and get things to work?Thanks. – SaH Jul 19 '16 at 16:31
26

I had similar issue.

Screenshot 1

Below are steps to resolve it:

  1. Navigate to folder where your projectName.xcodeproj.

    Screenshot 2

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

    Screenshot 3

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

    Screenshot 4

  4. 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

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

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
25

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.

Oleksiy Ivanov
  • 2,454
  • 15
  • 21
  • Thank you.. this makes much more sense than visual inspection – Ciprian Nov 26 '15 at 10:27
  • 2
    This helped tremendously. I just "tail -f /var/log/system.log" and tried to open the project. In the system.log, it showed an error (search for "Xcode") which showed the line number where the parse exception occurred. I then opened the file in vi and saw a control-character in the file (^H) and just removed that single character and voila! it was able to be opened. – DustinB May 10 '16 at 14:46
  • The best answer, rather than trying to do hit and try. Read Console Log. – Urmil Setia Aug 26 '16 at 02:10
  • 9
    Just try to build it from Terminal like xcodebuild -project Project.xcodeproj build. You will see the error right in Terminal. – Slavko Coolesoff Nov 23 '17 at 11:32
7

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.

beseder
  • 1,352
  • 2
  • 15
  • 25
3

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.

Abhi
  • 179
  • 10
3

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.

2

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

Vojta
  • 810
  • 10
  • 16
  • where is generated strings by git ? – Harshil Kotecha Apr 22 '17 at 05:50
  • These strings are conflict markers: "<<<<<<<", "=======" and ">>>>>>>". For more info about solving git conflicts look here: https://help.github.com/articles/resolving-a-merge-conflict-using-the-command-line/ – Vojta Apr 26 '17 at 06:53
  • @Vojta, could you throw that script in a gist? I am getting this error: `resolve_conflicts.sh: line 1: -d: command not found resolve_conflicts.sh: line 3: $tempfile: ambiguous redirect` – Daniel Jul 26 '19 at 23:52
  • Hi @Daniel , here it is: https://gist.github.com/vojtaBelovsky/0be156ff37929e16f55f253d8a97d808 – Vojta Jul 29 '19 at 11:17
1

Revert the project.pbxproj

svn revert --filename--

mondousage
  • 483
  • 1
  • 5
  • 14
1

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.

tyoc213
  • 1,223
  • 18
  • 21
  • Yes! Kin is a very good tool. I couldn't find the problem with **plutil -lint project.pbxproj**. The parser didn't find the exact lines with the problem and was placing the error at the end of the file. But with Kin, I was able to get the list of errors. – Elaine Herrera Jan 11 '23 at 19:41
1

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

0

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: User file cannot be parsed in subversion in MAC iphone SDK

Community
  • 1
  • 1
Atma
  • 29,141
  • 56
  • 198
  • 299
0

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

Avi Shim.
  • 1
  • 2
0

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

Ranch
  • 15
  • 4
0

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

suresh
  • 1
0

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.

Marc Charbonneau
  • 40,399
  • 3
  • 75
  • 82
  • 1
    Just check the project.pbproject file and do a diff against a working version of the project file. – Atma Jul 03 '12 at 18:06
0

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!

Brian C. Lane
  • 4,073
  • 1
  • 24
  • 23
0

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

Subramani
  • 477
  • 2
  • 14
0

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...

-2

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.

  • My guess is that you have the project opened in Xcode at the same time you do an update or commit..."IF" Xcode happen to autosave at the same time I'd guess some corruption can happen – epatel Mar 17 '09 at 23:25