I was trying to add a plist file to a xcode project through command line, some of the blogs suggested to edit the project.pbxproj
file. I searched about the project.pbxproj
file but was not able to get much information about it. Can anyone let me know what is use of the project.pbxproj
file in xcode? How does one add entries to it?
I am using this repo to work with it.
the script that I wrote is as follows:
import sys
import os
from mod_pbxproj import XcodeProject
def addPlistInProject(corodova_proj_name, xcode_proj_name, plist_file_name):
print "Cordova project name : " + corodova_proj_name
present_directory = os.getcwd()
path_to_xcode_proj = present_directory + '/' + corodova_proj_name + '/platforms/ios/' + xcode_proj_name + '.xcodeproj/project.pbxproj'
print "Xcode Project Path : " + path_to_xcode_proj
project = XcodeProject.Load(path_to_xcode_proj)
project.get_or_create_group('new group')
project.add_file(plist_file_name)
if __name__ == "__main__":
corodova_proj_name = sys.argv[1]
xcode_proj_name = sys.argv[2]
plist_file_name = sys.argv[3]
print "Xcode Project Name = : " + xcode_proj_name
print "Plist File Path = : " + plist_file_name
addPlistInProject(corodova_proj_name, xcode_proj_name, plist_file_name)
I will be invoking the script as:
python myscript.py hello HelloWorld manisha-rules_camdo.plist
myscript.py
is the script I wrote, hello
is the existing cordova project and HelloWorld
is the Xcode project created by using cordova platform add iOS
.
The command Sequence I will be following will be as follows:
cordova create hello com.example.hello HelloWorld
cordova platform add iOS
py myscript.py hello HelloWorld manisha-rules_camdo.plist
Where hello
is the name of cordova project and HelloWorld
name of iOS target.
Usually it is situated inside corresponding YourProjectName. xcodeproj package - it is a folder but looks like an ordinary file in MacOS's Finder - you can go into it right-clicking and choosing 'show package contents' option.
Right click your . xcodeproj file and "Show Package Contents". Then open project. pbxproj file with TextEdit and duplicate.
pbxproj is an old-style ASCII property list file, too. So you can use /usr/libexec/PlistBuddy to edit it. UPDATE: PlistBuddy will automatically convert project. pbxproj into a xml-format plist file since macOS Catalina or earlier version.
There is a Ruby API from Cocoapods for editing Xcode projects. It also have an active community of developers:
https://github.com/CocoaPods/Xcodeproj
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With