xcode 无法打开项目...无法打开,因为无法解析项目文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/361799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to open project... cannot be opened because the project file cannot be parsed
提问by Usuf
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...
我已经工作了一段时间来创建一个 iPhone 应用程序。今天当我的电池电量低时,我正在工作并不断保存我的源文件,然后电源就消失了......
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... ;-)
关于 SVN 的要点。我有一个,但是尝试将 XCode 与它同步时有些奇怪。我现在肯定会花更多的时间在上面...... ;-)
回答by Usuf
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
右键单击您的projectname.xcodeproj
文件,这里projectname
将是您的项目名称。现在右键单击后选择Show Packages Contents。之后,projectname.pbxproj
在文本编辑器中打开您的文件。现在搜索包含<<<<<<< .mine
,=======
和的行>>>>>>> .r
。例如在我的情况下它看起来像这样
<<<<<<< .mine
? ?9ADAAC6A15DCEF6A0019ACA8 .... in Resources */,
=======
? ?52FD7F3D15DCEAEF009E9322 ... in Resources */,
>>>>>>> .r269
Now remove those <<<<<<< .mine
, =======
and >>>>>>> .r
lines so it would look like this
现在删除那些<<<<<<< .mine
,=======
和>>>>>>> .r
线条,使其看起来像这样
? ?9ADAAC6A15DCEF6A0019ACA8 /* BuyPriceBtn.png in Resources */,
? ?52FD7F3D15DCEAEF009E9322 /* discussionForm.zip in Resources */,
Now save and open your Xcode project and build it. Everything will be fine.
现在保存并打开您的 Xcode 项目并构建它。一切都会好起来的。
回答by SnoopyProtocol
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.
穆罕默德的回答非常有帮助(并帮助解决了我的问题)。但是,在保留两个分支的更改时,简单地删除 >>>>>>> ======== <<<<<<< 并不足以解决 project.pbxproj(对我而言)中的解析问题合并后。
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.
我在 project.pbxproj 文件的 PBXGroup 部分(其开头由如下块注释指示:/* Begin PBXGroup section */)发生合并冲突。但是,我遇到的问题也可能出现在 project.pbxproj 文件的其他地方。
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.
通常,删除合并冲突标记将修复 project.pbxproj 文件中的解析问题并恢复工作区完整性。这次没有。
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.
我实际上不得不在第一个 PBXGroup 的末尾添加 2 行。
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.
您可以看到,如果我选择放弃来自 Head 或合并分支的更改,就不会有解析问题!但是,就我而言,我想保留从每个分支添加的两个组,仅删除合并标记是不够的;我不得不在 project.pbxproj 文件中添加额外的行以保持正确的格式。
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!
因此,如果您在认为已经解决了所有合并冲突后遇到了解析问题,您可能需要仔细查看 .pbxproj 并确保没有任何格式问题!
回答by bwags
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.
我遇到了完全相同的错误,因为 Cordova 将允许您创建一个包含空格的项目,而 Xcode 不知道如何处理。
回答by Jayprakash Dubey
I had similar issue.
我有类似的问题。
Below are steps to resolve it:
以下是解决它的步骤:
Navigate to folder where your
projectName.xcodeproj
.Right click and select '
Show Package Contents
'. You will be able to see list of files with.pbxproj
extension.Select
project.pbxproj
. Right click and open this file using 'Text Edit
'.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.Now, you'll be able to open project without any error message.
回答by Oleksiy Ivanov
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:
Xcode工程文件的可视化分析并没有帮助我在合并后定位错误。当 Xcode 尝试解析文件时,查看 syslog 后发现了这样的行:
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.
修复该项目后可以打开。
回答by beseder
Analyse the syntax of your project file. Check it inside your project in terminal:
分析项目文件的语法。在终端的项目中检查它:
plutil -lint project.pbxproj
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.
可能的问题:一些项目union
为项目文件设置了 git 合并策略。这在大多数情况下都有效,但如果失败,将无声地杀死您的项目文件。此策略.gitattributes
在存储库中的文件中定义。
回答by Abhi
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.
我的分支或远程分支中的 project.pbxproj 文件之间没有合并冲突。但是,我的 projectName.xcodeproj 文件将拒绝打开,原因与所问问题中所示的原因相同。
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 :
我的解决方案是使用文本编辑器查看 project.pbxproj 并查找文件语法中是否有任何违规行为(例如额外的大括号)。与合并文件相比,我通过关注在旧文件中插入或删除的行来加快这个过程。经过仔细检查,我发现问题的原因是重复了以下行:
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.
在我的合并文件中。这导致未闭合的大括号和随之而来的无效 pbxproj 语法。删除上面的行解决了我的问题。
回答by Vojta
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 Xcodeand open project when Xcode was closed.. then it worked. I hope this helps someone.
我刚刚遇到了同样的问题。我一如既往地通过 git 删除了生成的字符串,但 Xcode 仍然拒绝打开 .xcodeproj 文件。但一切都是正确的,没有缺少括号等。最后,当Xcode 关闭时,我尝试退出 Xcode并打开项目.. 然后它工作了。我希望这可以帮助别人。
EDIT:
编辑:
for resolving conflicts in your .xcodeproj file you can use this handy script:
要解决 .xcodeproj 文件中的冲突,您可以使用这个方便的脚本:
- Create empty .sh file in your project directory ( e.g. resolve_conflicts.sh )
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
Run it from terminal using sh command: sh resolve_conflicts.sh
- 在您的项目目录中创建空的 .sh 文件(例如 resolve_conflicts.sh )
这是脚本:
projectfile=
find -d . -name 'project.pbxproj'
projectdir=echo *.xcodeproj
projectfile="${projectdir}/project.pbxproj" tempfile="${projectdir}/project.pbxproj.out" savefile="${projectdir}/project.pbxproj.mergesave"猫 $projectfile | grep -v "<<<<<<< HEAD" | grep -v "======" | grep -v "^>>>>>>> " > $tempfile mv $tempfile $projectfile
使用 sh 命令从终端运行它:sh resolve_conflicts.sh
回答by mondousage
Revert the project.pbxproj
还原 project.pbxproj
svn revert --filename--
svn 恢复 --文件名--
回答by Akash Singh
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.
要遵循的步骤:- 1.导航到 projectName.xcodeproj 所在的文件夹 2.右键单击并选择“显示包内容”。您将能够看到扩展名为 .pbxproj 的文件列表。3.选择project.pbxproj。右键单击并使用“文本编辑”打开此文件。4.您将能够看到<<<<<<、============和>>>>>>>>>>。这些通常是从 Sourcetree/SVN/GITLAB 进行更新时出现的冲突。删除这些并保存文件。5.现在,您将能够在没有任何错误消息的情况下打开项目。