Cleaning up empty file references from collaborated Xcode projects - ios

What are these empty shells in my Xcode filesystem and what's the procedure to remove them safely? Also did a search for duplicate refs in the Xcode File Navigator but didn't find any.
Sidenote: Project is collaborated via git and I suspect that has something to do with their presence. Occasionally after merging feature branches we get conflicts in myproject.pbxproj file and must manually resolve conflicts by deleting duplicate file refs so maybe some slipped through. For anyone who's been in a similar mess: what's the standard way to clean it up?

Yes, I was facing the same issue while merging:
It is because of your project.pbxproj file not updated successfully. For each file we add, its reference is added in project.pbxproj file.here, these files is already having entry for your project.pbxproj file(like E00021389E899 if you look closure to your file) and another user also adds the same file then, 2 entries will be there in your project.pbxproj file for the same .h/.m thats why it is showing this error.
For cleanup purpose, you can simply right click and delete that file. There won't be any issue. and also don't forget to update your code regularly. If you ever have conflicts in your project.pbxproj, than you need to resolve it properly or try to get a fresh copy.

Related

Xcode showing duplicate project

Never seen this before. Xcode is displaying duplicate project although only single exists on the disk. I have tried refreshing the status from Source control and also checked remote repository, only one exists there. When I refer both in Show in finder, both point to the same location. My worry is if the location is same, and I try to delete any of them, the project will be deleted.
Please rename the project and the associated files without Xcode going mental, and without having to manually re-import all files to the project.

Duplicate files in Xcode manager?

I've found that I get duplicate files in the Xcode manager. They appear to point the same file in finder. My first thought is that this was created when one of my colleges was, incorrectly, fixing a conflict in the source control. I'm not sure how to fix the problem. When I try simply deleting a duplicate Xcode crashes. I've filed this buy with apple. However I would like to remedy this problem in the meantime.
Thank You.
I don't see any duplicates in your list. Every class comes with a .h and a .m file (there are exceptions). Long story short, there's not a problem with the image you posted.
Select one of the CMPortfolio.h files and one of the CMPortfolio.m files (one of the references, rather) and press the delete key. When asked whether you want to remove the references or actually move the files to the Trash, choose Remove References. This should remove the duplicate references while not touching the actual files on disk (which allows the remaining reference to each file to be valid).
I had the same problem. That helped me: I moved all duplicated files in some other folder in Finder -> all files in project were red. Then I simply deleted the files from project, copied the files in the project folder and added them to project again.

Project ...xcodeproj cannot be opened because it is missing its project.pbxproj file

I was trying to merge branches and it resulted in the error "Unable to open project… cannot be opened because the project file cannot be parsed". I then tried to take the advice of other stackoverflow responses (namely to edit the file to remove the corruption), but was unable to edit the file. It appears that this is actually a directory, so maybe the structure of this changed with version 4.4 of xcode and since the response to Unable to open project... cannot be opened because the project file cannot be parsed was written.
I then tried to restore myProject.xcodeproj from my time machine backup. This does not work because it says that I don't have permission to access myProject.xcodeproj. I tried to change the permission of that directory, but that did not help.
I closed and reopened xcode. Now the error is:
Project ...xcodeproj cannot be opened because it is missing its project.pbxproj file.
How can I fix this problem in xcode version 4.4? Can it be restored from the previous snapshot or archive or version in xcode. Can it be restored with time machine. I would like to avoid rebuilding the entire project.
The simplest thing to do is probably to
Checkout myProject.xcodeproj from source control. This will contain the changes that were causing you to be in conflict last time.
Redo the project changes that you made since the last time you committed to source control
commit/push to source control.
In the future, when you get a conflict in the project file, take a look at myProject.xcodeproj/project.pbxproj. Often it's just new files in the project that have been added at the same place. In this case you just need to delete the conflict metadata and resolve the conflicted state.
In the end, what I had to do was
'cp -R ...TimeMachineBackup/myProject.xcodeproj ...myProjectArea/myProject.xcodeproj'
Then I had to do the following in myProjectArea:
git reset --merge
This allowed me to open the project and switch branches back to my main branch.
not a pleasant experience
Another way this can happen is if you've been using sudo for some reason with pods or the editor - if the file exists under yourApp.xcodeprojectroj directory but xcode is complaining it can't find it - Go to your project root and do:
sudo chown -R yourusername:staff ./*
For others looking at this issue, the cause in my case turned out to be, that the "conflict text" from a git merge had crept into the actual file:
<<<<<<< HEAD
F0FDA2D61B99EB80007DB99D /* Aptron-mCollegix.xcassets */,
=======
F08CFAAA1BC1E9EE00A5B6F5 /* Aptron-mCollegix.xcassets */,
>>>>>>> hotfix/Column_Text_Cut-off
opening the project.pbxproj in a text editor made the fix easy.
I found my own solution to this issue.
The cause of the bug is that the .xcodeproj file is missing its containing pbxproj file, right? This is usually present when you right click your .xcodeproj file and click 'Show Package Contents'. However, in your own case, it's been deleted, through some mistake or other of git versioning.
As you can't really generate a .pbxproj file, the solution I found was to go to the original project folder location, which I had used to create the repository. To be honest, you could probably simply create a new project also, as long as it has the same bundle identifier and such! As this project's xcodeproj file will correctly contain a .pbxproj file, replacing the files in the XCode environment with your own project's files will allow the .pbxproj file to update based on these files.
Therefore, after opening this original project folder (/new project folder), in the XCode environment, I then removed all the files within the project, and replaced them with the corresponding files from my project which I was unable to open the xcodeproj file of. I had to fix a few resulting bugs here and there, stuff involving build phases and such not lining up, given you've just copied in a bunch of new files. But after fixing a few small errors, the same project in this new location was eventually able to run no problem!
Finally, I took this successfully running version of the project, and copied in all the files, .xcodeproj file, project folder, test files and all, into the original repository location, deleting the files from the repository before hand to avoid confusing overwriting of files (you can cut and paste the old repository files to a new location if you want to be safe, and don't fancy deleting them!). Then open the project in XCode from the repository location, build and run it on your simulator/device to make sure everything lines up (and fix any small bugs you may need to), and voila! Your project is now able to be committed, pushed, and ran!
This isn't the cleanest solution, and you may have to do similar things across various branches if they've all been corrupted. However, if you don't have access to a Mac time machine, and the other solutions aren't working for you, this is possibly the most straight forward way of having a working .pbxproj file again!
Oh, and I removed the .pbxproj from my gitignore. I'm not sure if it's actually find to have it in your gitignore or not, but I'd recommend doing your own research on that subject, I'm not certain myself!
Good luck!
I was able to get this working without commandline stuff like this:
Go to Time Machine drive in Finder.
Navigate to desired backup.
Drag it to where I want it. This will complain about not having permission to access the .pbxproj
Right-click the xcodeproj you just dragged out, select "Show Contents".
Right-click the xcodeproj in the Time Machine backup folder, select "Show Contents".
Drag the .pbxproj you see inside to the destnation you just created with the drag in #3.
Now it should work.
It seems you can generate the file again with:
swift package generate-xcodeproj
although you could see this message:
warning: Xcode can open and build Swift Packages directly. 'generate-xcodeproj' is no longer needed and will be deprecated soon.
generated: ./BokenEngine.xcodeproj
with xcodebuild > 13.4.1:
xcodebuild -version
Xcode 13.4.1
Build version 13F100
If anyone wants to find the missing project.pbxproj file then try opening the .xcodeproj with some code editor and you will find the file there. And note that i had backup of my application in my other pc so i found that file there so you mist have backup of your project somewhere in order for this to work.
In my case the issue was that there were actually 2 folders with .xcodeproj suffix
The actual one was located in MyApp/MyApp.xcodeproj
Somehow another one with the same name MyApp.xcodeproj got added to root folder, with the following contents:
project.xcworkspace/contents.xcworkspacedata
project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
So deleting this corrupt(?) xcodeproj solved the issue.

Xcode 4.2 (Snow Leopard) Build Warning "Missing File"

I recently deleted a viewcontroller from my project (both .h and .m files) but know I get a 'missing file' warning every time I build.
Any ideas on this and is it something I need to worry about?
Appreciated
This is probably a version control issue if you are using svn or git. I had this problem and solved it using the solution provided in this post:
Missing file warnings showing up after upgrade to XCode 4
I recently faced the same scenario. Adding and deleting did not work for me.
However, I added them once more and right clicked on them. Under source control, I Discarded the changes and then deleted the files(Move to trash). This worked for me !!!
Ensure that it's not referenced anywhere in the project.
Look at the files on the bar on the left, make sure it's not there. Missing files are colored in red.
Ensure that none of your files #import the file.
Also, in the future, avoid storing files in parent directories. ../../ isn't something you want to use.
You likely have a 'dangling reference' in your target's list of files to compile or copy -- check your compile and copy phases for the target which emits the warning.
If it's been physically deleted, the simplest way is usually to enter the file name into the project navigator's search field - look for what Tom detailed - then delete the files from the project(s).
I had a similiar problem. I was trying to delete a .h and .m and I wanted to remove the files entirely, but kept getting errors if I chose "Move to Trash" instead of just "Remove Reference".
Turns out, I needed to just delete each file INDIVIDUALLY. Just add the files back in (if you have them somewhere) and re-delete them one at a time. Worked for me!

How to remove reference of file Xcode?

I had removed some files from my iOS project a while back and thought they had been completely deleted. After a long time I created another class which unfortunately had the same name as one of those that I had removed from my project (but the reference nor the file had been removed).
To make the long story short, my project tried using the reference to the old file, so I went through finder to delete the conflicting files. That solved the issue of which class was being reference. But the reference to the deleted files cause a warning in Xcode giving me a Missing File message.
Does anyone know how I can remove the old references in order to get rid of this warning?
Since the reference to those files needed to be removed, I tried creating the files again under the same name as those that I had removed manually and deleted them again through Xcode and selected remove references from the pop up.
After removing a subproject, the framework was always referenced in my code.
To remove this framework I had to do these steps:
remove subproject (reference)
clean project
close xcode
remove all derived and cached data with this script run in applescript tool :
tell application "Terminal"
do script "rm -frd ~/Library/Developer/Xcode/DerivedData/*"
do script "rm -frd ~/Library/Caches/com.apple.dt.Xcode/*"
end tell
In my case, adding and removing the external frameworks and using Clean did not solve the problem. Going to Target > Build Settings > Search paths and removing the offending paths from Framework Search Paths and Library Search Paths did the trick.
I hit the same issue today. Due to git merge issue, I ended up with a image file removed, but reference to it still exists. To clarify, My intention was to remove the image.
The simple way to fix this would be using vim, or other text editors
vim PATH_TO_PROJECT/{#projectName}.xcodeproj/project.pbxproj
and do a search on the name of the file you deleted and just delete all search results there.
Go to Project > Build Phases > Compile Resources and select referenced Class and hit "-" .this Will delete reference And now Build Again.
To be safe from this error, make sure you Remove Reference on the file first before making any changes (outside XCode) on that file like deleting in folder, renaming, etc..
To remove reference, in XCode, right click on the file then Delete. A pop-up will show asking if you want to move to trash or remove reference.
However, that popup won't show if you made any changes before doing Delete on XCode.
Just a tip!

Resources