texture atlas file not found in main bundle in resources folder - ios

I'm having a problem where a file in my Resource directory is not being recognized as being in the Main Bundle.
I am creating a texture atlas using a pvr file format using texturePacker. The output of texturePacker produces two files xxx_iPhone-hd.pvr.ccz and xxx_iPhone-hd.plist. These two files are being stored in my Resource directory of my cocos2d project. Once the files are stored in the Resource folder, I go to the Resource folder and right click to 'Add Files to "myProject"' (with the copy items into destination box unchecked).
When my cocos2d project runs and tries to load this file, the absolute path is unknown to the Main Bundle. Specifically, my code executes the following line of code:
backgroundBgNode = [CCSpriteBatchNode batchNodeWithFile:#"StoreMenuBackground_iPhone.pvr.ccz"];
The cocos2d code knows that the device has a retina display and modifies the filename to create a relPath of "StoreMenuBackground_iPhone-hd.pvr.ccz". It then tries to execute the following:
NSString *imageDirectory = [relPath stringByDeletingLastPathComponent];
fullpath = [[NSBundle mainBundle] pathForResource:file
ofType:nil
inDirectory:imageDirectory];
This results in full path being nil. I previously created a different xxx_iPhone5-hd.pvr.ccz file with the above procedure, and the above code successfully returns the fullpath. I have very carefully checked and rechecked the spelling and don't see any problems. I have also tried removing and re-adding the files under "Copy Bundle Resources" of the "Build Phases" for the project. Is there something I can do to force the mainBundle to find this file?

You should verify that the file actually is in the bundle.
You can do that by right-clicking the built bundle (in your project's DerivedData folder) and select "Show Package Contents". If you don't know how to locate the built product, do an Archive Build targeting a device (archive builds are unavailable for simulators). In the Organizer window that opens right-click the app and select "Show in Finder", that brings you to the xcarchive. Run "show package contents" on the xcarchive and navigate to /Products/Applications and perform another "show package contents" on the bundle.
If the file is there but in a subfolder (not in the root of the bundle) then you have created a folder reference inside Xcode, denoted by the blue folder icon. Remove that and re-add, this time uncheck the checkbox "create folder references for..." in the Add File dialog.
If the file IS there, copy its filename and paste it back into code. Case differences can sometimes be elusive and hard to notice, even if you double-check.

desperate measures then. Copy in finder the files on the side ... ie not in the project directory structure. Rename the newly copied files to something dead simple , like a-hd.pvr.ccz and a.plist (hoping you dont already have an a-hd.pvr.ccz in your project ;) ).
Edit a-hd.plist to make certain that the last section points to the right file name. Drag them from Finder onto the xCode resources folder, selecting to copy the files. Make certain to change the name in your code. Delete the previous files from the project. Deep clean the project. Delete the app from the device. Run. If that worked, redo the same steps, reverting the name to your favourite name.

Related

Error: no such file or directory

My project was working perfectly fine. I then moved some files around from the project's root directory to some subfolders. Now, when I try to run the app, I receive this error message:
<unknown>:0: error: no such file or directory:
'/Users/anapaix/Desktop/currencyExchange/CommentsController.swift'
And I receive this same error for all 20 of the files that I moved around.
Additionally, the files now show up in red like this in my project:
When I double click the file, an empty Swift file shows up, like there is nothing inside. I have a feeling there should be some easy fix to this, in order for Xcode to recognize these files, but just have no idea what it would be.
You moved the files. Xcode doesn't know that. You need to tell Xcode where the files are. (Note: the other answers work too, but if you don't want to remove them and add them again, you can use this method)
Select your red file(s), open the File Inspector (Option+Command+1), and click the folder (circled in red in the below screenshot). Then find your file(s) and click Choose. The filenames should go back to being black.
If multiple red files are in the same folder, you can select multiple files in the Project Navigator (left column, Command+1), click the folder icon in the File Inspector (still the one circled in red, but the text will be different; it might say "multiple selected" or something) and click the folder containing the files. Xcode should automatically detect all of them, provided the filenames haven't changed.
Go Xcode->File->Add Files... and add missing files to the project.
when you move any file in finder from the projewct workspace then xcode doesn't recognize the new path automatically, and xcode consider it as deleted. So,Please remove this files that are in red colour in your explorer.
Then again drag the files from the finder in to your project.
This way your project found the new file path of files for the compling.

how to change path of iOS file to show project path

To manually include a number of “library” files into my project, I open my project in xCode. And then I open the “library” folder in finder. Then I drag and dropped from the folder into my project. But now when I go to Buid Phases > Compile Sources I see the path of the files I just copied to be …/download/… instead of /project/.... This is bad because when I push to git, the files aren’t passed along and they look red on the computer of anyone else who sync, for the obvious reason that the path specified does not exist on their machines. How do I fix this? As in, when I drag and drop I was expecting for the files to be copied and not just referenced. But they weren’t. Is there a simple fix? Note: I mark “copy items into destination group’s folder (if needed)”.
Also when I open my project in finder, the group that is supposed to have the "library" files isn't in there.
This is a tricky one. But I can assure you it is human error (well, I think anyway). Do this:
Right click on the group and select "show in finder". You will see that the group belongs somewhere else. So as long as you keep adding to the group, it won't really ever show up in your project. To fix, delete the whole group, type the group by hand, and then try drag and drop again.

Accidentally removed xcassets file from Xcode project

I wanted to remove a single folder from the image collection, however, I somehow managed to throw the entire xcassets file into the trash.
The normal 'Put back' method is not available, and simply dragging the deleted folder to Xcode yields an error:
"Images.xcassets" couldn't be copied to "ProjectPear" because an item with the same name already exists.
To save the file, either provide a different name, or move aside or
delete the existing file, and try again.
I'm not sure where this collection is located within my Xcode project, as the navigator doesn't appear to show anything, and the command-line isn't dropping any hints either. I'm afraid to mess around with the project.pbxproj file, as it might jumble up a lot more than just my image collection.
Edit:
Dragging the files back to Finder from Trash was successful, however, the Xcode navigator no longer recognises - or in this case, still doesn't recognise - the .xcassets file. I'm not sure whether to add something in the .pbxproj file.
I just did this myself and figured out how to quickly remedy the issue.
Go to the project folder in the Finder. You should find that the
folder Images.xcassets is still there.
Move it to a separate location like to the Desktop or something. It
still has all of the images and json files.
Jump back to Xcode and create a new asset catalog for images.
File > New > File... > Resource > Asset Catalog
Name it Images.
Quit Xcode and return to the Finder.
Copy the folders from within your old Images.xcassets to the new
Images.xcassets directory in your project.
Launch Xcode and you're back in business!
If you didn't delete it completely, you can just drag it back in from Finder. (Right click your project and select 'Reveal in Finder' to check)
If it's gone completely you simply go Cmd+N -> Resource and select Asset Catalog. You then re-add your imagages via drag and drop or right-click and 'Add Files to ...' and should be good to go.
Hope that helps.
Usually the file's reference is removed from Xcode, the original folder still exists in the project directory.
Right-click on your project folder, click "Add files to "your project"", find Assets in your project and click Add and you're
done
Had the same problem today with Xcode Beta, I also couldn't create a new assets catalog for some reason.
This was on a Watchkit Extension Project
Here's what I did to solve it:
In finder I copied an existing images.xcassets from another folder in my app to my desktop.
Removed the content of this folder.
Copied a deleted (single) Image Asset from my trash into the folder (on my desktop).
Dragged the entire folder into my project in XCode.
That fixed it and everything went back to normal.
If you have deleted it completely, then also these are the steps to get a new Images.xcassets:
In the Navigator, click on the project.
Go to : File>New>File> Add Asset Catalog> Name it.
To add AppIcon and LaunchImage in it:
Go to the Project Setting:
In General Tab, Slide down to App Icons and Launch Images
Click option next to App Icons Source and select Use Asset Catalogs
A window will pop up- select the name of your new Images.xcassets file and click on Migrate.
Select Also add LaunchImage. Now you can see the new Images.xcassets in your project :).
I accidentally deleted the reference to the asset folder so that it was no longer visible in Xcode. But when I checked from the finder, the asset folder was still in the project folder.
If you did that, just open the file menu in Xcode (from within your current project) and at the very top you can add (existing) files to that very project (back again) - it says "Add files to..."
Right click on anything in your project and click "Show in Finder". Search around in your project folder in the finder for a bit and you'll find it. I'm not on a Mac right now, or I'd give you a more direct path straight to the default .xcassets folder location.
And anyway, if you're not able to copy/create a "new" folder in that location because "an item with the same name already exists", then that means you didn't actually delete the folder. You just deleted your project's references to that folder in XCode. The folder on your hard drive didn't go anywhere.
[I realize this is a very old question from you #Aeveus]
All the answers talk about re-doing the adding assets again. Given you could not undo, the one step that is missing in your original description is this:
In your project.pbxproj file, there would have been references to assets as below:
45AE4E781C183FBA0051674F /* Assets.xcassets in Resources */ = {...
Assuming you have source code control system (git, etc) you can revert to the original contents of your project.pbxproj file, or manually just re-add the deleted lines, and re-open the project file in xcode. You are all set now.
I had the same problem. Open your XCode Project. Just go to File -> Add Files to...(your Project) -> Assets.xcassets and you are good to go!
I had same problem and I have followed the steps above from Jason, but finally i got Image.xassets in red color, so the in order to find my images I had to click in Image.xassets and then on the top right corner put the absolute path to my image.xassets folder and it fixed my problem.
Hope it helps!

contentsOfDirectoryAtPath: is not listing customized file extension

In my project (iOS), I have added some files with file extension (customized) ".dncx", for example. The customized file are visible in xcode project (Copt items into destination's.... checkbox is selected).
After using the following code, I'm printing the list of all the files.
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resourcePath error:nil];
The files with .png, .wav, .plist, .jpg, extensions, all are getting printed, which are present in the same path along with customized files.
But the files with the customized extension like, ".dncx" are not at all shown.
Could you please guide me, making the customized file extensions listed.
Those files are obviously not in the directory that you think they are. I've put some dncx file in my bundle (and in Documents) without incident.
Typical problems include:
If you're looking for these files in your bundle, the question is whether they were included in the bundle at all. If you open your target settings, choose "Build Phases" tab, expand "Copy Bundle Resources" and see if your dcnx files are listed there; if not, add them there by clicking the "+" button immediately at the end of the list of "Copy Bundle Resources";
Again, if you're looking for these files in your bundle, make sure they weren't accidentally put in another folder within the bundle;
If you want to externally confirm the contents of your bundle or Documents folder, I would run the app on the simulator and then navigate to the folder in question (e.g. "~/Library/Application Support/iPhone Simulator/ ..." and see if they're there ... you might want to go to Terminal and type in chflags nohidden ~/Library if your Library folder is hidden in Finder (which it is by default)). To see inside the bundle, once you've navigated to the app itself, control-click on that (or right-click) and choose "Show Package Contents"

move xcode project causes red text (missing files from project)

When I move iphone project directory to a new path.
There are some red texts indicate the missing files from the project source codes.
How to avoid these?
Here is how to locate the missing (red) files using the Xcode 4 interface:
Select the file or files in the left hand Project Navigator (the folder icon)
In the right sidebar click on "File Inspector" which is the leftmost icon resembling a page
In the "Identity and Type" section, there is a grey box labeled "Location".
Click on the small icon to the lower left that resembles a file browser - this will come up with a file browser to locate the file.
Voila, you are done.
Xcode 7
1.) Right click on the red (missing) file.
2.) Select "Show File Inspector"
3.) Look at the right hand side of the screen under "Identity and Type" between "Location" and "Full Path"
4.) Click on the folder icon to the right of the file name.
5.) Navigate to the file's new location in the pop-up window and select the file.
I encountered this issue when copying my project from one mac to another.
The solution for me:
assuming your files are grouped (in folder)
from xcode open the group in file inspector
The group will probably be missing the absolute path.
press the little icon nearby to pick the folder to associate the group with.
restart xcode to see the changes.
I had the same problem, when I changed the permission on the files/folders to everyone read/write they then appeared in Xcode.
This worked on a Pod project. Quit XCode.
rm -rf project.xcworkspace/xcuserdata/*
Restart XCode and reopen project.
In Finder, create a duplicate of the project directory just in case all goes squiffy.
In Finder, open the project directory that contains all the files with red references
For all the red files you see in XCode, except the info.plist file (see step 5 below), highlight them in Finder and drag them from Finder to XCode's project navigator. i.e. import them.
In XCode's "Choose options for adding these files" window: a) Select Copy items into Destination's group folder (if needed)
b) Select Create groups for any added folder
c) Select Add to Targets, and press Finish
Highlight and drag the info.plist file from Finder to Project Navigator and repeat step 4 WITHOUT selecting Add to Targets
If you had groups in Project Navigator (e.g. Supporting Files), reorder the files to be in the right places.
Delete the original bad red references in Project Navigator, and Cmd-Shift-K to clean for good measure.
Build and run on a device to remove the bad reference to the .app file
you just have to locate the missing file press in file icon in the identity and type you will find the full path just locate your file where do you move it click the file icon
When you create these files be sure to save in your app directory. Or if you import classes from other project be sure to check the copy option.
I dont know if this is the main reason but when you are importing files to the application, do you mary the "Copy items in to destination group's folder (if needed)" ?
this make sure the file is not only referenced but added to your project folder and ir will move any where you move your project.
Did you move files in to folders directly in your project folder and not in xcode?
This worked on a Pod project.
go into finder and project.
right click on your project .xcworkspace and click show package contents
right click on contents.xcworkspacedata and open with textEdit then make sure file path is correct. If project has been moved this can change
I also did this below but now sure if you need it
Quit XCode.
rm -rf project.xcworkspace/xcuserdata/*
Restart XCode and reopen project.
If you create an Xcode project, then move the .xcodeproj file or the newly created project folder to a different folder using Finder, subsequent builds may show many missing files which still reference the original folder locations (which no longer exist because you moved them). These missing files can appear as red text or as issues in the Issue Navigator.
This can happen when Xcode is configured to automatically add or remove files to/from source control (under Xcode > Preferences > Source Control). When configured this way, simply creating a project in Xcode causes new project folders and files to be marked for addition to source control. When you later move the project folder or .xcodeproj file these pending adds now point to missing files.
To resolve this issue when Subversion is the source control program, revert the pending adds for the phantom items from your local working copy folder. In my case this requires dropping into a Terminal window, navigating to the parent of the phantom project folder, then reverting the automatic add, e.g.
cd /my-working-copy-folder
svn status --depth infinity
svn status --depth infinity existing-parent-folder/phantom-project-folder/
svn revert --depth infinity existing-parent-folder/phantom-project-folder/
Note that the first svn status command will list both missing files as well as properly added, modified or deleted files which you must take care to avoid reverting. The second status command is "practice" for the final revert command, to ensure you've specified the proper path to revert.
I do not know git but I assume it offers corresponding commands.
It's too simple to do :
Close the project that includes the missed files and open the Xcode, go to "Organizer">"Projects" and remove the project from the list there. Open your project from Finder and that's it.
hope this help.

Resources