无法打开项目... 无法打开,因为无法分析项目文件

我已经为开发一个 iPhone 应用程序工作了一段时间。今天我的电池没电了,我正在工作,不断地保存我的源文件,然后停电了..。

现在,当我把我的电脑重新插上电源时,我试图打开我的项目文件,却发现一个错误:

无法打开项目

无法打开项目... ,因为无法分析项目文件。

有没有什么办法能让大家知道我能从中恢复过来?我尝试使用一个较旧的项目文件并重新插入它,然后进行编译。它给我一个时髦的错误,这可能是因为它没有找到所有它想要的文件..。

如果可能的话,我真的不想从头开始重建我的项目。


剪辑

好的,我对这个和稍微老一点的项目文件进行了区分,发现文件中有一些损坏。在合并它们(好的和最新的部分)之后,它现在正在工作。

关于 SVN 的好点子。我有一个,但有一些时髦的尝试同步 XCode 与它。我现在一定会花更多的时间在它上面... ; -)

enter image description here

109511 次浏览

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.

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!

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.

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

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

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.

Revert the project.pbxproj

svn revert --filename--

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.

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.

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

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

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!

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.

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

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.

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.

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

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.

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

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.

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