We are creating a framework and want to offer an easy way for a user to add it in their project. Possibly a script which will add framework into the project without any xcode interaction.
mod-pbxproj appears to be an option but also looking for other options, preferably shell script based options.
I looked at .pbxproj file and I think it would be straightforward to copy and add framework files, however, some inputs of structure will be appreciated.
Please do not suggest Cocoapods/Carthage, we are looking for 100% command line option and both these options require some form of xcode interaction.
Related
I have my own framework which I've made. I use this framework in another project I made. That is, after building my framework, Dragged the Product, .framework to Embedded Binaries of project.
However, I've to continuously make changes to the framework. So the process of dragging and dropping again and again is a lot of work. How to conquer this ?
Can someone tell the exact steps even if it means including the project as well ?
Copy the framework Project to your project folder.
Open your Project in xcode.
Right click on the Project File on left side of xcode and click on option "Add file to Project Name" and then select the framework project here.
Delete the Product .framework available in the embedded libraries and add the framework product properly.
So your goal is to 'deploy' changes made to .framework to all the projects you've already embedded it in previously. Here is one approach to it.
Create [myFramework]Targets.txt file where you'll be putting all the locations (directories) of your framework in different projects, line by line. It will have something like this:
~/Path/to/project/A/Frameworks
~/Path/to/project/B/Frameworks
~/Path/to/project/C/Frameworks
Create deploy_framework.sh file with script that will replace your framework everywhere you need. I'm definitely not the one you can call a Bash expert, by here is what it probably looks like:
for destination in $(<[myFramework]Targets.txt); do /bin/cp -rf /Path/to/updated/[myFramework].framework "$destination"; done
Now, whenever you're done with your framework changes, just run deploy_framework.sh from Terminal. Assuming your Xcode projects have existing reference to .framework and you didn't change its name, it should work.
NOTE: You might still need to do Clean+Build for your projects to compile with updated framework. I believe you can also tweak project settings to 'cache' builds less aggressively.
Let me know if it works for you, we might need to adjust script a bit, since I never tested it.
I was reading a blog to better understanding the purpose of making a project for sublime (or any editor):
When you save your code as a project you end up with two files. The
first is the project file which contains references to folders for
your project, project based settings and build commands for your
project. The second file is the workspace. This is simply a file that
tracks what layout you're currently using and what files you have open
in each pane. Using the workspace file means that you can switch to
another project, do some work and then switchback to your original
project knowing that the layout and files you had open will be
restored back to the state you left them in. Handy.
So seems like there's 2 reasons? 1. is to save settings and 2. is to save the current layout of the files and folders you have already opened? I see reason 2 to be nice, but not really super important. What are some of the settings in reason 1 that's important to keep in between projects? What is a build command?
You might simply have to follow different coding standards for different customers, e.g. indentation rules, so its handy that you can set these rules on a per project basis.
A build system let's you run or compile code directly from Sublime Text.
Background
I'm porting a small Windows application to iOS using XCode 6.2 as both the IDE and build platform. I have a workspace created, which I'm using to compile and build all the projects. I currently build every project except the actual iOS app as a dynamic library, and then embed it in the final app package on deployment.
The Problem
I'm currently hard coding relative paths in the projects. Stuff like ../../shared-headers - I really don't like doing this as I have to figure out this path per project, and I'd prefer to use something like props files in Visual Studio, which would let me do something like $(SHARED_HEADERS) in projects.
This makes the projects easier to maintain, and any dependency extremely obvious. It also makes it much easier to move projects when the need arises. What is the preferred method to do this in XCode?
EDIT: I'd like to stick with a Visual Studio-ish include structure. While Copying headers is a good way to manage some of the complexity, I do not prefer this method because it will add time to the build, and developers from Windows will not be expecting this.
I too was looking for the same thing, and i've just found it! using an xcconfig file!
Create a .xcconfig file either from xcode's file menu or just a simple text file, and add your entires like so:
PATH_TO_SOME_SDK = Volumes/DEV/Project
SOME_DEFINITION = 7
once you add that file to the project, you can add it (or different ones) to each configuration in the project's info panel under "Configuration".
the definitions along with their values will then appear in the project's build settings under "User-Defined", and will change dynamically as the value in the file changes.
you can then use the values in any other build setting like any other environment variable or macro:
$(PATH_TO_SOME_SDK)
for more info:
https://nshipster.com/xcconfig
https://medium.com/better-programming/working-with-xcode-configuration-files-398cfbe02b64
https://help.apple.com/xcode/#/dev745c5c974
better late than never...
:-)
I am looking for a way to add libraries to an Xcode project, using the command line.
I have been successful in adding files to groups with the XCS tool, but it does not support libraries.
I would, for example, like to be able to add CoreVideo.framework to a specific project with a command on the Terminal.
This project can handle frameworks:
https://github.com/kronenthaler/mod-pbxproj
Just add it as a normal file, it will figure out the correct type and how to set everything up (i.e., add it to the link library phase – before using it, you still need to import the header(s), of course).
// libFilePath: Path to the framework
frameworkGroup = project.get_or_create_group('Frameworks')
project.add_file(libFilePath,
parent=frameworkGroup,
tree='SDKROOT',
weak=True)
You can decide whether you want to weak-link frameworks (see code example) or not (just leave out the last parameter, it defaults to False). You can find the code to open/save Xcode projects in the repository.
Another way to do it is adding linker flags directly, e.g., -framework CoreVideo.framework. If the framework paths are set up correctly, you don't have to provide absolute paths. The disadvantage of this approach is that the linked frameworks aren't obvious if you open the Xcode project, as they are not part of the link library section, nor does the framework show up in any Xcode group in the Project Navigator.
You can try generating your .xcodeproj using tools like XcodeGen. It allows you to include different types of dependencies.
Okay, here's a little bit of context:
I have just added a Mac OS Core Data Command Line Tool target to my iOS project. It's purpose is to simply use my iOS app's Core Data model and a JSON file (which I am adding default data to as I go) to create an SQLite database which I am going to use as the default database for my iOS app. The idea is to have this command line tool ready in my project so that when I add some default data to my JSON file, I just:
Run the command line tool
Go to products in the file navigator on the left
Control click the command line tool product and hit show in finder
Drag the .sqlite database that has been displayed along with all the other bundled files for my command line tool and drop it into my iOS app's resources
But, I can't do this because the command line tool product is showing red in the navigator window because Xcode is looking for it at this path:
/Users/kylejm/Library/Developer/Xcode/DerivedData/MyiOSApp-ggjlxrqiijmbqkgkucdargamkwld/Build/Products/Debug-iphoneos/
Where as the it is actually in:
/Users/kylejm/Library/Developer/Xcode/DerivedData/MyiOSApp-ggjlxrqiijmbqkgkucdargamkwld/Build/Products/Debug/
I have been inspecting the Build Locations in the Build Settings but all the resolved paths are correct for both my iOS app and the command line tool respectively.
What do I need to do to make Xcode look in the right place?
Thanks so much for any help in advance.
I just clarified my scenario/problem for the answer by bauerMusic like so:
Thanks for your answer but I don't think you quite understand my scenario or problem. The Command Line Tool (CLT) target is a part of my project, and therefore has a executable product in the product folder (shown in red until first build and run). When I run this command line tool, it's product in the products folder remains red because Xcode is looking for the product in the wrong place for it.
I've put it in the description so you all understand my question as clearly as possible.
You usually never add files to a project outside of Xcode, (meaning, simply place it in the folder) unless you want to have these sort of issues.
Try to remove it, restart the project (build and see that it has no broken links warnings), and drag the file to the navigator's folder in your open Xcode project.
Edit: Just to be clear, add through Xcode, not the Finder. Xcode should prompt you to either copy resource or not (check box).
I was going to suggest you Clean the project, but I then noticed how you actually added the file.