I know this has been answered for a while, but since the original question is about tools supporting the manipulation of .pbxproj
files, and many other people may be looking for the same information, here's how I do it. It took me quite a while to figure this out because I was very unfamiliar with Xcode when I started attempting this, so I hope this saves others the hours of grief I had to put in.
You can use the plutil
command to transform the .pbxproj
file from the legacy .plist
format into an XML or JSON format you will be able to manipulate more easily. I'm using JSON. To do so, just run:
plutil -convert json project.pbxproj
This will convert the format of project.pbxproj
, but be aware that -contrary to common sense- the output won't be another file with a JSON extention such as project.json
. What will happen is that project.pbxproj
will be converted to JSON format, but retain it's cryptic .pbxproj
extension. So even though the file's format has been changed, Xcode will still pick it up and use it in its new JSON format.
Then you can change project.pbxproj
with ease using any JSON manipulation tool of your choosing. I'm using Groovy's JsonSlurper
class in a Groovy script.
Note I also explored the XML option, but I found the project.pbxproj
file in XML format to be cumbersome to parse. The elements are not properly nested to allow for traversing the tree with ease. It's plagued with:
<key>someKey</key>
<dict>
<!--More elements which provide configuration for the key above-->
</dict>
So it's positional in nature. You have to look for the key
element corresponding to the setting you want to manipulate and then jump to the dict
element just after it. Which means you have to mount the children of each XML element into an array, in order to index them.
.pbxproj
file? – Aramaic*.xcconfig
files, plus auser defined fields
may redefine from cmd line. This is a build step fromteamcity CI
:xcodebuild -project 'MyApp.xcodeproj' -scheme 'MyAppStaticTeamcity' -configuration 'Debug' -sdk 'iphoneos' GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS NS_BLOCK_ASSERTIONS=1 MY_LOG_LEVEL=2' clean build
– Aramaic"USER_DEFINED_VARIABLE=${hi}"
?? – Cordiform* .plist
as a setting. Replacement a value in the* .plist
much easier than editing the project file or pass the user defined field (seeplistbuddy
). In my project I have the settingserver_address
which placed in the*.plist
. – Aramaicproject.pbxproj
is aplist
file, too. So you can use/usr/libexec/PlistBuddy
to edit it. – Suzanxcconfig
is a much better way thanproject.pbxproj
file. Andperl
is good at editingxcconfig
file. – Suzan