27

I was trying to merge branches and it resulted in the error "Unable to open project… cannot be opened because the project file cannot be parsed". I then tried to take the advice of other stackoverflow responses (namely to edit the file to remove the corruption), but was unable to edit the file. It appears that this is actually a directory, so maybe the structure of this changed with version 4.4 of xcode and since the response to Unable to open project... cannot be opened because the project file cannot be parsed was written.

I then tried to restore myProject.xcodeproj from my time machine backup. This does not work because it says that I don't have permission to access myProject.xcodeproj. I tried to change the permission of that directory, but that did not help.

I closed and reopened xcode. Now the error is:

Project ...xcodeproj cannot be opened because it is missing its project.pbxproj file.

How can I fix this problem in xcode version 4.4? Can it be restored from the previous snapshot or archive or version in xcode. Can it be restored with time machine. I would like to avoid rebuilding the entire project.

10 Answers 10

10

Another way this can happen is if you've been using sudo for some reason with pods or the editor - if the file exists under yourApp.xcodeprojectroj directory but xcode is complaining it can't find it - Go to your project root and do:

sudo chown -R yourusername:staff ./*
0
8

The simplest thing to do is probably to

  1. Checkout myProject.xcodeproj from source control. This will contain the changes that were causing you to be in conflict last time.
  2. Redo the project changes that you made since the last time you committed to source control
  3. commit/push to source control.

In the future, when you get a conflict in the project file, take a look at myProject.xcodeproj/project.pbxproj. Often it's just new files in the project that have been added at the same place. In this case you just need to delete the conflict metadata and resolve the conflicted state.

3
  • 1
    boxel, I tried the following (Jeffs-iMac$ /usr/local/git/bin/git checkout myProject.xcodeproj), but got the following error. I am not knowledgeable about git. Can you provide further advice? error: path 'myProject.xcodeproj/project.pbxproj' is unmerged
    – JeffB6688
    Aug 27, 2012 at 14:25
  • I'm not an expert either, but I'd try 'git reset myProject.xcodeproj/project.pbxproj' followed by 'git checkout myProject.xcodeproj/project.pbxproj'. But first, backup the entire directory structure somewhere to be sure that you have something to revert back to.
    – boxel
    Aug 27, 2012 at 14:58
  • boxel, thanks. I did not get a chance to try your last suggestion. Instead I followed the steps I posted in my own answer where I used a unix cp command to restore the directory. But thanks for taking the time to answer my question.
    – JeffB6688
    Aug 27, 2012 at 16:05
6

In the end, what I had to do was

'cp -R ...TimeMachineBackup/myProject.xcodeproj ...myProjectArea/myProject.xcodeproj'

Then I had to do the following in myProjectArea:

git reset --merge

This allowed me to open the project and switch branches back to my main branch.

not a pleasant experience

3

For others looking at this issue, the cause in my case turned out to be, that the "conflict text" from a git merge had crept into the actual file:

<<<<<<< HEAD
                F0FDA2D61B99EB80007DB99D /* Aptron-mCollegix.xcassets */,
=======
                F08CFAAA1BC1E9EE00A5B6F5 /* Aptron-mCollegix.xcassets */,
>>>>>>> hotfix/Column_Text_Cut-off

opening the project.pbxproj in a text editor made the fix easy.

2
  • which is to delete from here and what? Dec 1, 2017 at 13:43
  • Sorry, I haven't been using this account much. The last ".xcassets" line is good, the rest is cruft from a diff that shouldn't be in the file.
    – RayInNoIL
    Mar 26, 2018 at 22:17
3

I found my own solution to this issue.

The cause of the bug is that the .xcodeproj file is missing its containing pbxproj file, right? This is usually present when you right click your .xcodeproj file and click 'Show Package Contents'. However, in your own case, it's been deleted, through some mistake or other of git versioning.

As you can't really generate a .pbxproj file, the solution I found was to go to the original project folder location, which I had used to create the repository. To be honest, you could probably simply create a new project also, as long as it has the same bundle identifier and such! As this project's xcodeproj file will correctly contain a .pbxproj file, replacing the files in the XCode environment with your own project's files will allow the .pbxproj file to update based on these files.

Therefore, after opening this original project folder (/new project folder), in the XCode environment, I then removed all the files within the project, and replaced them with the corresponding files from my project which I was unable to open the xcodeproj file of. I had to fix a few resulting bugs here and there, stuff involving build phases and such not lining up, given you've just copied in a bunch of new files. But after fixing a few small errors, the same project in this new location was eventually able to run no problem!

Finally, I took this successfully running version of the project, and copied in all the files, .xcodeproj file, project folder, test files and all, into the original repository location, deleting the files from the repository before hand to avoid confusing overwriting of files (you can cut and paste the old repository files to a new location if you want to be safe, and don't fancy deleting them!). Then open the project in XCode from the repository location, build and run it on your simulator/device to make sure everything lines up (and fix any small bugs you may need to), and voila! Your project is now able to be committed, pushed, and ran!

This isn't the cleanest solution, and you may have to do similar things across various branches if they've all been corrupted. However, if you don't have access to a Mac time machine, and the other solutions aren't working for you, this is possibly the most straight forward way of having a working .pbxproj file again!

Oh, and I removed the .pbxproj from my gitignore. I'm not sure if it's actually find to have it in your gitignore or not, but I'd recommend doing your own research on that subject, I'm not certain myself!

Good luck!

2

I was able to get this working without commandline stuff like this:

  1. Go to Time Machine drive in Finder.
  2. Navigate to desired backup.
  3. Drag it to where I want it. This will complain about not having permission to access the .pbxproj
  4. Right-click the xcodeproj you just dragged out, select "Show Contents".
  5. Right-click the xcodeproj in the Time Machine backup folder, select "Show Contents".
  6. Drag the .pbxproj you see inside to the destnation you just created with the drag in #3.

Now it should work.

1

It seems you can generate the file again with:

swift package generate-xcodeproj

although you could see this message:

warning: Xcode can open and build Swift Packages directly. 'generate-xcodeproj' is no longer needed and will be deprecated soon.
generated: ./BokenEngine.xcodeproj

with xcodebuild > 13.4.1:

xcodebuild -version
Xcode 13.4.1
Build version 13F100
0

If anyone wants to find the missing project.pbxproj file then try opening the .xcodeproj with some code editor and you will find the file there. And note that i had backup of my application in my other pc so i found that file there so you mist have backup of your project somewhere in order for this to work.

1
  • in my case i changed the name bundler name abc.com.app1 to something else and this caused the xcode to move previous xcode project in a hidden file at same folder, so i deleted the new xcode file and used the previous old xcode file that was hidden and my problem was solved.
    – Farhan
    Sep 20, 2018 at 10:49
0

In my case the issue was that there were actually 2 folders with .xcodeproj suffix

  1. The actual one was located in MyApp/MyApp.xcodeproj
  2. Somehow another one with the same name MyApp.xcodeproj got added to root folder, with the following contents:
project.xcworkspace/contents.xcworkspacedata
project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist

So deleting this corrupt(?) xcodeproj solved the issue.

0

Following solution works if you have the original project on mac A, you pushed your code on source control, you cloned your project on mac B and now it says.

"Project pathToProject/projectName.xcodeproj cannot be opened because it is missing its project.pbxproj file."

Solution:

  1. Go to project directory on mac A where you created the project for the first time.
  2. Right click on xx.xcodeproj(where xx is your project name).
  3. Click on Show package contents.
  4. Copy project.pbxproj
  5. Go to project directory on mac B where you cloned the project.
  6. Right click on xx.xcodeproj(where xx is your project name).
  7. Paste the copied file here.
  8. Now try to run your project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.