iOS - Adding multiple targets to the same project? - ios

I am trying to add 3 targets to my existing project. Dev, QA, and Prod.
The problem is that when I rename the target, during the build it looks for the target name as my project root folder, so I get a bunch of build error because all my header search path, library search paths are now broke.
Is it possible to make it so that Xcode uses the same project root name regardless of what the target name is?

Did you change the name in the box below? I had similar problems with names getting out of kilt, and it turned out this was the key if I recall. I should add if you have one target and want to duplicate it, you can select the one, then right click and get a duplicate contextual menu.
EDIT: Then, go to the Manage Schemes and make sure the name is correct there, and not "Project Copy". If all else fails grep you project in Terminal looking for "Copy" - you might have to edit the project file with vi (with it closed in Xcode!)

I found out what the problem was: $(SRCROOT)/$(PRODUCT_NAME) in my frameworks search path. $PRODUCT_NAME is being used to find the root directory of the project, and since all the targets are pointing to the same project I ended up hard-coing the project name. $(SRCROOT)/MyProject.

Related

Xcode - changing search path for frameworks

I'm having an issue with frameworks not being recognized:
For some reason the path for the frame work is set to Derived Data folder:
Is there anyway to change this to point the frameworks search the right folder?
Also, what kind of language is this and how would I go about changing the directory to the proper module (in the repo)?
Thank you for any insights you can provide, this is confusing for an amateur like me.
Is there anyway to change this to point the frameworks search the right folder?
Yes, and you seem to have found the Framework Search Paths setting in the project already. Change that setting to include your frameworks folder and Xcode should start seeing your frameworks.
Also, what kind of language is this and how would I go about changing the directory to the proper module
It's not a language at all, its just a list. When you double-click in the right-hand column of the setting, as you've done in the image above, a view opens that lets you edit the list. It's not shown in your image, but at the bottom of that view there are + and - buttons — click the + and you'll add another item to the list. You can add your folder there.
The $DEVELOPER_FRAMEWORKS_DIR item that you see in the list is just the value of the DEVELOPER_FRAMEWORKS_DIR project variable. Each of the settings in the build settings have a corresponding variable that the setting changes — the variable for each setting is listed in the Quick Help panel for that setting. The $(inherited) is a sort of macro within the Xcode build system — it specifies the values that have been inherited for that build setting from other settings levels. See What is $(inherited) in Xcode's search path settings? for more information about inherited.
You shouldn't add an absolute path to the Framework Search Paths setting, e.g. one that starts with /Users/yourname/Library/... because then the project will only build on your machine. Instead, you should specify the path relative to some point in the project, and the various environment variables in Xcode can help. If you want to specify a folder called Frameworks at the top level of the project directory, for example, you could add an item to Framework Search Paths that says $PROJECT_DIR/Frameworks. You can find a list of project variables here: How do I print a list of "Build Settings" in Xcode project?

Error after renaming Xcode 6 project: "linker command failed with exit code 1 (use -v to see invocation)"

So after I create an Xcode 6 project, even if I haven't written any code in it, if I try renaming it by double clicking the bolded program title in the upper left hand corner of the navigator and then confirming that I want the checked items' names changed, I get the following error when I try running it: "clang: error: linker command failed with exit code 1 (use -v to see invocation)"
I've even tried using the find tool to see all the things named the previous name, including the info.plist (which I think is the problem) and changing them to the new name. By renaming the info.plist manually I get an error saying that doesn't exist.
What am I doing wrong?
I saw the same error after changing the name, and I was able to fix it by clearing the "Test Host" values in the Build Settings of my "Tests" target:
Alternatively, If you need your tests to be able to run after changing the name of your project, you should be able to update the MyProject.app/MyProject value in both fields to reflect the new name of your project (ie. MyNewProject.app/MyNewProject)
If above method(s) doesn't work and if for now you don't feel like needing to test anything in your project, just remove your project test target.
Later on if you need to create some tests, you will still be able to add test targets again.
Go to the Build Settings of my "Tests" target then change the paths from the old project name to your new project name
Test Host
- Debug Build/Debug-iphoneos/OldProjectName.app/OldProjectName
- Release Build/Release-iphoneos/OldProjectName.app/OldProjectName
Test Host
- Debug Build/Debug-iphoneos/NewProjectName.app/NewProjectName
- Release Build/Release-iphoneos/NewProjectName.app/NewProjectName
Just simply clearing them would break your tests so you need to replace them with the new project name.
Ran into this too, after copying and renaming the folder with an xcode project. I think it's a bug in xcode. Best file a bug with bugreporter (https://bugreport.apple.com/). Removing the test target from my project fixed it for me, too.
Here is what I've done to fix the similar problem since I changed the project name and folders under the project.
Select project file : projectName.xcodeproj
Right click on the project file and click "Show package contents" to open project.pbxproj file.
Once ope project.pbxproj file, replace all from old project name (whatever you changed from) to new name.
You can change the name of sub folder if you changed folder name too.
Hope this help.
There are different places where you should check for the rename.
You should check for the "old" project name in the test target and in the project target. Search for the old name string and rename them manually to the new name.
If you doesn't use the test target you can delete this target.
There are many places you have to check upon re-naming. This approach does not seem at all practical.
If you really need to do this, I recommend creating a new project and just copying the necessary files over to the new project.

directory not found Apple Mach-O linker warning but Library Search Path and Framework Search Path are empty

I'm getting these messages:
ld: warning: directory not found for option '-F"/Users/joel/Development/GHaikuTabbed"'
ld: warning: directory not found for option '-F"/Users/joel/Development/GHaikuTabbed/../../../Downloads"'
But when I go to Build Settings (as suggested at ‘ld: warning: directory not found for option’), Library Search Path and Framework Search Path are empty, so there's nothing to delete.
Thoughts on other things I can do to get rid of this warning?
Here is a description how to avoid a problem based on Apple Dev Forum posted before. It works for me so I repost description for those people who don't want to go and register at the forum.
The bug is due to an error in XCode 5 when it deals with the user adding new files or folders to the project.
Xcode is modifying the 'Library Search Paths' build setting, and making a god-awful mess of it.
Instead of adding $(SRCROOT)/ it is adding fully rooted paths to all new items, and adding random amounts of /// into other elements of the string.
It also seems to be duplicating source paths in some instances, probably because it's broken the existing ones, and thinks they need adding again.
The solution:
Copy out your Library Search Paths string into a text editor.
Remove any fully rooted paths that shouldn't be there, and replace them with the usual $(SRCROOT)/MyFiles/ type paths.
Remove all extraneous slashes and make sure each path has a " character at beginning and end to protect against spaces in filenames.
Paste the edited string back into Build Settings.
Clean, then Build. Should be back to normal.
This error may well recur if you add new files to your project, so beware.
My project.pbxproj looked like this:
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\\\"$(SRCROOT)/AdMob-v6.4.1\\\"",
"/MyProject/AdMob-v6.5.1",
);
I closed MyProject, deleted the line containing AdMob-v6.4.1, reopened the project, performed a "validate project settings", cleaned, and built, and now all is well.
Yeah, Xcode is jenky sometimes.
Did you try cleaning your build (Product > Clean Build Folder / Shift-Cmd-K) and trying again?
Another thing you can do is to search for the two entries in [project_name].xcodeproj/project.pbxproj, remove them, close XCode, re-open, Clean Build Folder and try again.
Good luck!
To summarise what #user2963906 is suggest, I show my solution to this problem, which I think much easy.
I assume that you have all your files and libraries in your project folder.
Open your project Targets
Find Search Paths topic and Library Search Paths
Choose and remove all paths here
Then add path like this: $(SRCROOT)/"Your App Name"
In the same window change drop-down list from the right from non-recursive to recursive
Shift-⌘-K and Run your project
I found a solution for this with my case on the iOS Developer Forums. It happened to me with Xcode 5. See Massive Linker Error Warnings (directory not found for option) yet . For me it was caused by Xcode 5 junking up the "Library Search Paths" build setting.
Easy Solution :
It's work for me
when you want to add new files or folders to the project through xcode 5 and above error display.Just follow below simple step.(Please don't forgot to get backup of your project).
Open your Project in Old XCode (I recommend XCode 4.6.3)
Add your files or folder. (it will not mess your library search path as it mess in XCode 5)
Close the old xcode and open your project with XCode 5 and start to code.
I faced the same problem but was unable to fix it as per the steps since no library folders were getting displayed in the Project properties window.
So I solved it in another way (you need to be able to use the Terminal and the VIM editor. Also take a backup of the project just in case)
Open a Terminal window
Go to the project folder.
The XCode project is a folder. use cd project name to go into that folder.
use vim to open and edit the project.pbxproj file.
Remove reference to the offending lines by searching using / and using the dd command on that line to delete it.
Save using :wq command
Open the project in XCode and build. Works like a charm.
I had to escape any spaces with a \
So for example:
/Users/Me/Folder\ with\ spaces\(and\ brackets\)
in Library Search Paths
This worked for me :
Create this real directories (with no content), add them to project, remove via remove reference, clean, delete for real
In project folder -> target , under 'Build Setting' search 'library search paths' and simply delete previous path in Debug & Release area.
Now add the line below line using + symbol
$(PROJECT_DIR)/Library
Note: After adding the above line click out from popup. its automatically display the full path.Then check this path with your Finder if any correction add after the $(PROJECT_DIR)/
Clean , Build and Run … Simple its cleared that error. :)
-Anup

Adding frameworks to project in Xcode 5 and having *relative* paths added

All of a sudden today I get an unexpected problem with Xcode (5).
This is how I normally add an external framework:
Drag-n-drop the file (xxx.framework etc) (or the folder which contains the file) into the project manager.
In "Choose options for adding files" I check "Copy items into destination (if needed)" only if needed (if the files are already in the project's folder I don't do this)
In "Folders" I select Create groups for any added folders
And I add it to my app target.
Normally this would also add the relative path(s) to the framework in Build Settings/Framework Search Paths and Library Search Paths.
However today the path that shows up there is direct (aka absolute). This breaks stuff down the line because the paths should be relative. How come Xcode does this all of a sudden? I suspect it might have to do with this one project only (it comes from a 3rd part dev) and something about their project setup could be causing this.
I faced the same issue. There is a simple fix. Go to framework search paths. Remove everything from there. Add ./ and make it recursive. That's it.
I am having the same problem on XCode 5, so far the best solution is to modify the path of your framework search.
Go to your project
Build settings->Framework search path
Add the relative path to your framework.
If it was correctly copied now you can modify the path, to something like this:
./MyProject/Libraries/ACoolLibrary
Supposing a file structure like this:
-MyProject.xcodeproj
-MyProject
--Libraries
-----ACoolLibrary
-------- TheCoolLibrary.framework

Two targets, two header files with the same name how to use each header for the right target?

Ok, here's what I've tried.
I have the header files in two separate directories IRL. They're named the same, but are in two different locations.
I want to only include the relevant header file for each target. Lets say for ease of explaination that the header file is called "Config.h".
So I have:
${PRODUCT_DIR}/Header1/Config.h
and
${PRODUCT_DIR}/Header2/Config.h
These files appear in the LHS of Xcode as well in two different groups (Header1 and Header2 which point to the IRL folders).
So now all I need to do is to make Xcode choose the right one from the right folder for each target.
Target1
and
Target2
I have tried adding the path to the User Header Search Paths for each target, but its still choosing the wrong one. I've also tried toggling "Always search user paths" which also doesn't seem to have an effect.
So my question is, is this because they're in the Project directory? Or is it because they're in Xcode in the file manager on the LHS, so therefore Xcode is copying them into the build folder?
The strange thing is it seems to be choosing the header files from the folder with the last name alphabetically...
In previous versions of Xcode I'm sure you could choose which headers to copy into the build folder.
Anyway.. does anyone know how I can fix this so that I can have it select the proper header file for the target?
Many thanks.
The problem I was having was 2 fold:
You need to remove the header files from the project. If they're in Xcode, in the file manager, then they will automatically be included in the project.
You need to use relative paths to your folders in "User Header Search Paths". I was using ${PROJECT_DIR}/path/to/header/folder which gave the right path, but didn't seem to work properly. Changing the entry to ./path/to/header/folder instead worked fine.
I have 4 targets in 1 proyect and more than 40 headers, the best solution in XCode 8
I think the best solution is change the following tag:
Always Search user Paths
To yes an all was fine for me:

Resources