Some files not visible in xcode. But they are visible in finder - xcode

I am writing test cases for IOS. For that I created a new target for "IOS UI Testing" bundle and some files for writing test cases.
It created a folder "UITests" with some test files in it.
The problem is they are not visible in the xcode after xcode is restarted.
I am able to find the code in the finder and they are also recognized by the git. But not able to find them in the xcode
What might be the reason for this unpredictable behaviour?
Here's a screenshot of my xcode project, after I add the files manually.
Now, I can see the files, but I am unable to run my tests as it gives me error "Cannot load underlying module for XCTest".

I got the answer. Thanks to #HunaidHassan.
whenever you do add a new target or a file. It gets referenced in the .pbxproj file. It saves the references of all the project files and its hierarchy.
I was discarding the changes done to pbxproj file, therby removing the references of newly created targets and files, which caused the files to disappear from the xcode

Related

Problems after upgrading to Xcode 10: Build input file cannot be found

I upgraded my Xcode SDK to version 10 last night and then find I cannot build.
I'm getting this error:
Build input file cannot be found:
'/Users/call01/Library/Developer/Xcode/DerivedData/Comp-Lite-Apps-gytvmossqptokeafrddvvmnlzadk/Build/Products/Debug-iphoneos/SG11.app/SG11
which did not exist before my upgrade and I'm tempted to revert back but would like to stick with version 10 if I can resolve this issue.
Try to switch back to the Legacy Build System (File > Project Settings > Workspace Settings > Legacy Build System)
For Swift files or files that belong to the project such as:
Build input file cannot be found: PATH/TO/FILE/FILE.swift
This issue can happen when files or folders have been removed or moved in the project.
To fix it:
Go in the project-navigator, select your project
Select Build Phasestab
In Compile Sources section, check for the file(s) that Xcode is complaining of
Notice that the file(s) have the wrong path, and delete them by clicking on the minus icon
Re-add the file(s) by clicking the plus icon and search in the project.
Product > Clean Build Folder
Build
You generally find these missing files in the Recovered References folder of Xcode in the project tree (look for the search bar at the bottom-left of Xcode and search for your complaining file):
Deleting them from this folder can also solve the error.
For me In Xcode 10, this solution worked like a charm. Just go to the Recovered References folder and remove all files in red color and add it again with proper reference.
If Recovered References folder was not found: Check for all missing files in the project (files in red colour) and try to add files references again.
Just check the path to .plist file in Build Settings of your target
Funnily, closing Xcode and reopening it might also be enough.
This worked for me in Xcode 10:
Click Project icon/name in your Xcode project
Go to General tab
Click [Choose info.plist File] under Identity section
Select the info.Plist file
Check Info tab to see if info.plist was loaded successfully
Build and run
This is an architecture problem. Do not change to legacy build system!
I got the same error, but what solved it for me was this:
The top says architectures in VALID_ARCHS are also excluded in EXCLUDED ARCHS. I was messing around with them to get a Swift Package to compile in Xcode 12, and have spent hours on this.
It would compile on the simulator and not on a device.
The Solution:
Go to Build Settings
Ensure "Architectures" contains 1 entry : $(ARCHS_STANDARD)
Ensure there is nothing in "Excluded Architectures"
Now scroll right to the bottom of Build Settings.
Make sure the VALID_ARCHS is exactly the same as this screenshot.
The arm stuff is $(ARCHS_STANDARD) again.
If VALID_ARCHS doesn't exist, add it with the + button.
Clean (cmd-shift-K)
Your project should now build perfect on both the simulator and device!
If it doesn't work, you need to make sure all these settings are the same both in your target build settings and the project build settings.
Note, if you have a Mac with Apple silicon, you may not need to do any of this.
The above solution eventually works for me; however, I need to do some more extra steps to finally make it to compile successfully. (These extra steps were required even on Xcode 9.)
Xcode: File -> Workspace Settings -> Build System: Legacy Build System
Xcode: Product -> Clean
Rotate to compile thru different emulator types, such as "iPhone 8", "iPhone 8 Plus", etc. (They might fail or might not.)
Eventually compile on "Generic iOS Device"
I fixed this issue this way: go to your project's Build Phases (click on project icon at the top, and then click on Build Phases). Search for your file there. If it's there (it'll be grayed out), delete it. Then clean (shift + alt + command + k), and run! Hope it helps.
If the error says it can't find Info.plist and it's looking in the wrong path, do the following:
Select your project from the navigator, then select your target
Select "Build Settings" and search "plist"
There should be an option called Info.plist File. Change the location to the correct one.
None of the above worked for me, but this did:
Open project in Finder, right click on your .xcodeproj file and show package contents
Open project.pbxproj in a text editor
Find the reference to your missing file
Edit path = "path/to/file.swift" to the actual location on disk and save the file.
Rebuild the project
In my case I had a build script that generated the .app binary (Buck).
The Buck build script ran in parallel with Swift Embed build step. Because the .app binary was not generated yet the Swift step would fail.
In my build script I added "$BUILD_PRODUCTS_DIR/$EXECUTABLE_PATH" under "Output Files".
This tells Xcode's New Build System that this script will output the app Binary and in turn Xcode will make sure to synchronize any build steps that depend on this artifact.
I ran into this error after renaming a file. Somehow Xcode didn't correctly rename the actual file on disk.
So it wasn't able to find the file. Sometimes the files gets highlights with a red text color. At other times the Swift icon in front of the file was getting a gray overlay.
The fix was simple.
Look into the error and see exactly which file it's unable to find.
Select the file that can't be found.
Go to the 'File Inspector'. It's on Xcode's right navigation pane.
Click on the folder icon.
Select the correct file.
Clean build and run it again.
Open the right navigation pane where your project files exist
OR JUST click on cmd + 1. Then search for "Recovered References" folder. Open it and delete all red files, then everything will work so fine.
I had this happen for building my unit tests. This may have happened because I deleted the example tests.
I removed the Unit test bundle then re-added it as shown in the pictures below and all was well again.
I had a similar issue after upgrading to a new swift version recently.
Moving files around caused my xcode project to reference items that were no longer in the project directory giving me the Error Code Build Input File Not Found.
In my situation I somehow had multiple files/images that were being referenced as described below:
In the image above.
Navigate to your Targets page.
Then Click on the Build Phases tab on the top.
Scroll Down to Copy Bundle Resources
Find the affected files and remove them. (hit delete on them or select them and hit the minus button )
It was in here that I somehow had multiple files and images that were being referenced from other folders and the build would fail as they could no longer find them. And I could not find them either! or how Xcode was still referencing them
I hope this helps someone else !
This worked for me
try deleting the red colored files
delete the files in derived data
clean the build folder
then try building by using "new build system" from file->workspace settings
I had the same issue. The problem was that I didn't have any file under the Target > Build Phases > Compile Sources. The problem was solved after I added at leas one file to Compile Sources.
Not that I did anything wrong, but I ran into this issue for a completely different reason and kinda know what caused this.
I previously used finder and dragged a file into my project's directory/folder. I didn't drag into Xcode. To make Xcode include that file into the project, I had to drag it into Xcode myself later again.
But when I switched to a new branch which didn't have that file (nor it needed to), Xcode was giving me this error:
Build input file cannot be found:
'/Users/honey/Documents/xp/xpios/powerup/Models
Extensions/CGSize+Extension.swift'
I did clean build folder and delete my derived data, but it didn't work until I restarted my Xcode.
In my case, the file (and the directory) that XCode was mentioning was incorrect, and the issue started occurring after a Git merge with a relatively huge branch. To fix the same, I did the following steps:
Searched for the file in the directory system of XCode.
Found the errored file highlighted in red (i.e, it was missing).
Right clicked on the file and removed the file.
I tried building my code again, and voila, it was successful.
I hope these steps help someone out.
What Xcode was complaining about was a XIB file I got it working by going to Project -> Build Phases -> Copy Bundle Resources, removing the "problematic" XIB, cleaning (CMD+Shift+K), building and adding it back again.
There is also one possibility that sometimes when you move your files to different folder and especially when you move your info.plist to other folder, you need to define the location of that file. To solve this problem, simply click on your project blue icon on the top, and you will see a button in place of project name and bundle id, click on it and locate the info.plist file there, clean and compile happily.
I ran into this problem soon after upgrading to Xcode 10, but that was not the issue.
I tried changing the build system, but that gave me a separate error that meant the same thing. Generally saying "File X can not be found".
There are multiple things to check when a file can not be found.
Recovered references Folder
Apple does this nice thing where if it detects a reference to a file that doesn't exists it will add this reference into a group called "Recovered References"
That is nice of Apple but it doesn't always work.
Build Phases Compile Sources
In this list, there could be meta data for a file that the project is suppose to compile, but the file does not actually exists and it's attempting to find the file at the given path. In this list it will be dimmed out, delete them and re-add them by toggling the file's target dependencies or manually removing it and dragging it in.
File's Path
Double check the file path that the error is printing out and the file path for the file in finder. You can easily see this by clicking on the file in Xcode and checking the "Show the file inspector" tab (the left most tab). If these paths are correct then you are good!
Dimmed out files in your project that are not in recovered references or red
This one pissed me off because it's not obvious about what happened, but basically if you go into finder and move a file to a different location with out updating the reference in the project it will throw the error as the file no longer exists there. The only indication I have found for that is that the file in the "Project Navigator" tab (left most tab) is very slightly dimmed, but when you go to delete this file Xcode doesn't prompt you to delete the reference or send to trash. You can fix this by deleting the file and re-adding it to the project or going to the "File Inspector" tab and click the folder icon next to the path and change it to the proper location.
Either way, the error indicates that it can't find a file, switching to the old build system is a bandaid for a more concrete issue. We as developers understand that a compiler just wants an artifact to be listed at the end of a file path. Somewhere the path is not correct! We have to find where that is!
My issue was resolved with item 4 listed above. Hope this helps somebody.
In my case I accidentally deleted one third-party xcodeproj folder I used in my app.
If you tried profiling, and then it didn't work, and now you cannot build, go into your Target pane (via the Project Icon), Switch to the Build Settings tab, search for PROFILE - and set CLANG_USE_OPTIMIZATION_PROFILE to "No".
In my case, I had created a new test target and deleted the default swift file so it was left with just the info.plist. Adding a new file fixed this.
The "Legacy Build System" solution didn't work for me. What worked it was:
Clean project and remove "DerivedData".
Remove input files not found from project (only references, don't delete files).
Build (=> will generate errors related to missing files).
Add files again to project.
Build (=> should SUCCEED).
I know that this is an old subject, but I found the issue with xcode 12.3 and was related to an error while doing the CopyPlist of the main.Storyboard during compilation.
Actually, changing the build settings to "Legacy Build Setting" worked, but it is deprecated, so I discarded it because is a short term solution.
Check this:
With that setting, worked for me. Before I had "Copy plist".
After struggling with this issue for about 45mins, here is a super easy solution that worked for me.
On the project explorer, click on the file/folder that is in red colour (means project is not able to locate the file)
Look at the details tab in the file inspector (generally to the right of the screen - see the attached screenshot)
Click on the folder icon and locate the real file/folder in your local machine.
That is it. This should do the trick. Basically help your xcode locate the directories and update the reference cache.
Random, for Cocoapods: I hadn't added my test target to my Podfile.

Changing the name of main folder in Xcode project

This is not the first time I've had trouble with this and I suspect not the last time either. Despite having learned many frameworks inside out I still find the organizational structure of a simple xcode project elusive. I simply wanted to retitle a project from CATouchSynth to ABTouchSynth. A while ago I discovered that if you click on the Project folder in project navigator and than change the name in the Identity and Type section it will rename many of the relevant files and directories to the new name. However, there is one main folder inside the folder on your computer that doesn't change and still has the old name. I could see no way to change this folder name through Xcode and so I renamed it manually from finder. This turned all of my source files and assets red so I manually "relinked" them in xcode and they are now non-red and seemingly linked with the newly named folder. However I am getting several compile-time errors talking about the old folder name but I have no clue what Xcode is referring too. The errors look like this
It seemed as if derived data was an issue so I deleted the derived data folder from Xcode and I still get these errors. Has anyone experienced this before and what can I do to ressurrect my project?
Note: Before doing any changes do backup your project folder. This is seriously recommended.
Follow the steps below to rename the source folder of your project –
Close XCode.
Rename the Source Folder.
Right click the project bundle .xcodeproj file and select “Show Package Contents” from the context menu. Open the .pbxproj file with any text editor (Xcode).
This step should be done with extreme caution. Search and replace any occurrence of the original folder name with the new folder name.
Save and Close the file.
Open XCode project.
The error is happening at build time during the compile phase, so you will have to go into the app target's Compile Sources build phase, remove all those .m files, and add them again.

xcodeproj file is missing

I have folder where i store all my projects. I have problem with one of them.
All projects except this have projectname.xcodeproj file.
When i open Xcode i see this project - it has icon with white background (other have blue background). I can open it, build and run.
I can't find this .xcodeproj file - so i can't run pod init in terminal for this folder. I See error "No xcode project found, please specify one".
I don't use git. Searching for this file had no results. What else can i do?
I think you may have changed the path for the specific project you're experiencing problems with. Try to create another project and just copy/paste the files from the old project into the new one and reference the new project.

Managing source files in Xcode

I was moving some files around in an Xcode project and deleted some files in finder (I know). I've broken my project and now I can't figure out how to fix it.
At the moment I'm getting an Undefined symbols for architecture x86_64: error when trying to build. The files however, are actually in the project and physically in the project directory. I added them to compiled sources, but I'm still getting the same error.
I don't understand how Xcode manages the source files and I haven't found any good information on how to troubleshoot these problems. Googling basically tells me to not delete files (too late) and I can't find anything in the Mac Developer documents.
How can I get my source files back in order so I can build this project?
EDIT: I noticed this in compiled sources:
The files that are causing the problems are the ones that don't have "...in Worker" next to them (Worker is the name of the project).
When you try to delete a file, then two options pop up: Remove reference or Move to trash.
If you select Remove reference, then you file is present in the project file directory. You just need to goto finder->your project and add that missing file.
If you select move to trash, then goto Trash, select file, right click and select put back.
If still you are getting error "Undefined symbols for architecture x86_64", then closely observe the error, in the last line of error, some variable name/class name is written there which is missing. Either that variable is declared multiple time or not declared.
I don't understand how Xcode manages the source files
It really doesn't. You add files to the project, and Xcode updates the project file with the fact that those files are in the project and their location on disk. If files go missing from the project (Xcode can't find them because you moved or deleted them), those file names are displayed in red in the project navigator.
So, start by looking for red filenames in the project navigator. Those are files you need to put back. If you're not sure where they were before, or if you want to move them to some other location, you can also just delete them from the project and then add them again.
At the moment I'm getting an Undefined symbols for architecture x86_64: error
That may mean that you've forgotten to add some file or other to a specific target. If you select a source file in the project navigator and look at the file inspector, there's a section called "Target Membership" where you can see which targets the file is part of. If you've just added a file to the project, make sure that the checkboxes next to all the targets that depend on that file are checked.
Go to "Build Phrases -> Copy Bundle Resources" and remove those files which are represented in Red color text.
Also make sure that in your project navigator you should remove those missing files as you deleted them physically from your project directory.
Hope this helps!

Multiple errors ocurred while copying files - but, can I see what they are?

There were around 200 files I had to delete in my Xcode project (and yeah, they were deleted properly), and now I have to copy 200+ files are supposedly replace the ones I just deleted.
I keep getting "Multiple errors occurred while copying files". The Xcode window doesn't show the newly-added files, but if I explore the project folder using the Finder, I can see that the files were indeed added - well, there most likely was a certain file that could not be copied and thus caused the error. Problem is, I have no idea which one nor why.
Now then, is it possible to get Xcode to tell me what the problem is rather than telling me there is one?
Edit: Okay, I did discover that some of the new files shared the same name as some files that were not listed in Xcode, which explains the error. However, I am still interested in knowing whether there is a way to know that the "Multiple errors" actually are whenever Xcode says t his.
When Xcode finds a duplicate file, it generates this error, and then it fails to add references for the files that it did manage to copy.
Rather than deleting files from the finder and starting over, you can do this:
Open the Finder for your project, where your source files are located
Command-click the ones for which your references are missing (and if you click others, it won't really matter)
Drag them into Xcode. When the confirmation dialog comes up, unset the "Copy items into destination group's folder (if needed)" checkbox. This will tell Xcode to make references only.
I deleted the files from finder and then added again the files via Xcode, that worked for me.
This error sometimes occurs when the code is not merged properly. The missing files will not be available in Xcode but once you open the finder containing this project, you will be able to spot the missing file.
The simplest way to add these missing files back to the project is:
1) In your Xcode, navigate to Build Phases Tab.
2) Under Compile Sources, tap on '+' to add back the missing file.
Sometimes the missing files will be greyed out in the build phases, just tap on '-' and add them back.
For me this is worked. I tried to add files which are already in my bundle. So make sure you are not adding files which are already added. I hope it helps someone.

Resources