Library to read/write pbxproj/xcodeproj files?
The surface syntax of an Xcode project is an "old-style plist." You can easily convert it to an XML plist with the command
plutil -convert xml1 -o - myproj.xcodeproj/project.pbxproj
Note this is not "real XML" but the Mac OS X plist structure expressed in XML syntax; it consists almost entirely of key-value pair dictionaries and arrays. Xcode will read the XML representation but convert it back to "old-style plist" when the project is opened.
The structure and relationship of the items in the plist follow the structure of the project. The UUIDs are used to cross-reference items between the project and its targets, and between the project and the user files in the project wrapper.
The 'isa' key identifies each kind of object. The PBXProject contains PBXFileReference, PBXGroup, PBXNativeTarget, and PBXBuildConfiguration objects.
The targets have PBXBuildPhase objects that contain cross-references to the file references; BuildConfigurationLists that store the build settings for the targets, and other target settings like the target type and name.
The buildConfigurationLists cross-reference buildConfigurations, which in turn contain dictionaries of buildSettings.
I'd recommend looking at the old-style plist text first, as it's much more readable and actually has inline comments to tell you what's what. Then you can use XML tools to edit or write the project files to your liking.
Why my project.pbxproj file changes its format
@Lumialxk
I had a very similar thing occur yesterday. Similar in that my project.pbxproj
file was in plist format, different in that I did not get a File 'project.pbxproj' is broken
message. Instead, the issue surfaced for me via a merge conflict. Where the conflict was in the project.pbxproj
file. There was one conflict and it was the entire contents of the file. In other words there were two versions of the file. One on my new branch where it was in plist format. And one on our base branch where it was in the normal JSON-like format. Either way, it sounds like the same thing you are seeing.
Important to note that both branches pre-merge worked with Xcode. Xcode didn't seem to have an issue with the plist formatted project.pbxproj
file.
I solved the issue by doing a git reset --hard HEAD
to throw away my attempted merge, this got me back to a point where I had a branch with a plist project.pbxproj
file that I could build and run without issue. I then chose a random build setting (code signing), changed its value and then changed it back (i.e. I just "touched" it to force Xcode to modify it). I then built the project. And then re-opened the project.pbxproj
file in a text editor. After having "touched" the file it was back in the normal format, no more plist format.
From there it was smooth sailing.
Credit goes to my co-worker for suggesting the "touch" approach.
I'm not sure what caused the issue. Here are some details about my setup:
I'm running Xcode 7.3 (so I don't think it had anything to do with 7.3.1). I recently upgraded from Cocoapods 0.39.0 to 1.0. I think this is the culprit. I ran into issues building some pods with 1.0 which I resolved by forcing the use of 0.39.0 like this:
pod _0.39.0_ install
pod _0.39.0_ update
Hope this helps!
Looking for a formal specification for .pbxproj files
You can start with this introduction. Then look at some kind of reference here.
There is also Apple's description of core concepts (projects, targets, workspaces, schemes).
Project ...xcodeproj cannot be opened because it is missing its project.pbxproj file
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
Add files to Xcode project through command line ? Use of project.pbxproj file in Xcode?
There is a Ruby API from Cocoapods for editing Xcode projects. It also have an active community of developers:
https://github.com/CocoaPods/Xcodeproj
How to Add project.pbxproj File For Json Framework in iOS and Suitable Framework
Your errors sound like they are related to you including too much of what you downloaded. Those errors are probably related to the demos and such included in the SBJson package that you shouldn't have in your project. If you just want the SBJson abilities I would recommend just adding the SBJson files to your project directly. You can just copy over everything under the /Classes folder and build.
How to list all files for one target in Xcode
Unfortunately, I'm unaware of any environment variables available to a build script.
The best way that I know of would be to open the pbxproj
file inside your xcodeproj
bundle and parse it. Luckily, it seems to be in a plain text format compatible with plists
. You could invoke the plutil
command to convert it to XML or json for another tool/command to consume if that is your goal. You can utilize a "Run Script" build phase if you need this list as part of your build. You can also instantiate an NSDictionary
directly with that file if that is useful to you.
The plist
is pretty simple. It consists of a root
dictionary with some version strings and a giant objects
dictionary. Each object has an isa
type and the one you are interested in is the PBXNativeTarget
type. Scan until you find the target with the correct value for the name
key. Once you find your target look at its buildPhases
; AFICT the first entry in buildPhases
is the key for the corresponding PBXSourcesBuildPhase
object. That build phase object has a files
array which contains yet another set of IDs (one for each file compiled into the target) which point to a PBXBuildFile
object, which has a fileRef
string as a key to another object, this time to a PBXFileReference
. This object finally has a path
key which will be the path to the source file.
Wait... did I say "simple"?
Near duplicate lines in pbxproj files, are they important?
Usually Xcode generates unique reference(ID's) for files referenced in multiple targets.
I suppose you are having more than one build targets and LoginViewController referenced in both which ends up with different fileRef ID's.
Although it looks identical but removing them assuming that it might be harmless may cause crashes.
You can read more about pbxproj file from http://www.monobjc.net/xcode-project-file-format.html.
Related Topics
Android - Change App Theme on Onclick
Java - Process.Destroy() Source Code for Linux
Expected Begin_Array But Was Begin_Object at Line 1 Column 2
Default Constructor VS. Inline Field Initialization
Java Method to Swap Primitives
Hibernate Criteria Returns Children Multiple Times with Fetchtype.Eager
How Does Java Do Modulus Calculations with Negative Numbers
Parsing a String to Date Format in Java Defaults Date to 1 and Month to January
How to Convert a Java 8 Intstream to a List
How to Get Pid of Process I'Ve Just Started Within Java Program
Webview and Cookies on Android
Detect Touch Press VS Long Press VS Movement
Inputstream.Available() Is 0 Always
What Is the Purpose of Java's Unary Plus Operator
Reusing a Preparedstatement Multiple Times