74

I am trying port my iPad project to latest iPad 2. I installed iOS 4.3 SDK with Xcode 4.0. When i try to build my project, i'm getting the following error. I don't know why am i getting this error. Could someone help me to resolve this build error?

While reading /Users/username/Desktop/iPAD/MyProject/trunk/Resourses/images/top_bar.png pngcrush caught libpng error: Not a PNG file..

Could not find file: /Users/username/Library/Developer/Xcode/DerivedData/Project-fmhveawksgdtnraclfizuhrekmzi/Build/Products/Debug-iphoneos/MyApp-Upgraded.app/top_bar.png

Getsy
  • 4,887
  • 16
  • 78
  • 139
  • Also to convert the multiple images to png in a folder in single step use terminal. Using cd goto the folder containing the images (JPGs or any type). run Code: mkdir pngs; sips -s format png *.* --out pngs It will convert your images to .png and will create a pngs folder contain the converted images.[Also see](http://stackoverflow.com/questions/13679710/not-a-png-filcommand-copypng-emitted-errors-but-did-not-return-a-nonzero-exit-co/13679813#13679813) – HDdeveloper Mar 19 '13 at 04:04
  • I faced a similar problem and posted a solution that worked for me [here](http://stackoverflow.com/a/39496092/1425768). It also happens when you have multiple images with the same name in your project and **copy resource to bundles**. – Anup H Sep 14 '16 at 19:16

15 Answers15

89

I had the same problem, but it wasn't because of a corrupted png : it was because two PNG files had the same filename in different directories of my source tree. What was peculiar was that the errors (I had 4 files which had "twins") were not identical from one build to another. On one run I had errors on all files, on the other only on some of them.

Guillaume Laurent
  • 1,734
  • 14
  • 11
  • 2
    This happened to me. I opened a project I hadn't been using for a couple of days, and after two or three builds, this. Weird... – Nicolas Miari Jun 18 '12 at 19:49
  • Possibly both versions were added to your copy-files build phase; at least that was the problem for me. – Pascal Apr 13 '13 at 20:26
60

Did you check whether the file Users/kavapanga/Desktop/iPAD/ALN II 3 latest 2/trunk/Resourses/images/CS_logo_for_top_bar.png exists? Also check if it is infact a PNG file. Right click on the file and do a Get Info to check if the file has any other extension and is marked as hide extension. If you are not sure of the format of the file, opening the file and save it as a PNG file again should work ,most of the time.

Besi
  • 22,579
  • 24
  • 131
  • 223
Krishna
  • 1,871
  • 14
  • 26
  • Hi Krishna, Yes, i see the file is available with the .png format. – Getsy Mar 22 '11 at 06:50
  • 2
    Could you please try saving it as a PNG once again? – Krishna Mar 22 '11 at 06:52
  • Hi Krishna, As you said, i saved again as .PNG format. It is not giving build error now. But, when i try to install on my iPad 2 through Xcode 4(all the settings are done), it shows "Finished Running MyApp-iPad" , but i'm not seeing the app installed on my iPad. What could be reason? – Getsy Mar 22 '11 at 06:54
  • That will be difficult to answer without knowing a lot of details about your app. Did you look at the logs in the console as the app runs? Also, can you run it in debug mode with break point? – Krishna Mar 22 '11 at 07:00
  • Ok. Now i am just trying to run in iPad 4.3 Simulator, it builds completely and finally stuck at "Attaching to MyApp-iPad" for long time..Any idea? – Getsy Mar 22 '11 at 07:09
  • Not sure. May be you could close this and post this as a new question to get more eyes on it. – Krishna Mar 22 '11 at 07:20
  • No problems. I am able to install by changing it to proper target as "Release". Thanks for your help! – Getsy Mar 22 '11 at 07:25
  • 1
    I think it just got upvoted but not accepted. Not sure why. Did you click on the tick mark against the answer? – Krishna Mar 22 '11 at 07:38
  • Just did it, please check. Btw, i have one more question, how do i debug the project into iPad 2. I tried choosing Debug target and then tried installing the app, but it installed but then Xcode quits with this error "Error starting Executable MyApp-iPad" "Error launching remote program: failed to get the task for process 462." Any idea on this? Sorry for querying all in this same question itself. – Getsy Mar 22 '11 at 07:47
  • I have not tried on an iPad 2. Is it a physical iPad or the simulator? Again I suggest moving it to a separate question so that more people can look at it and help in quick resolution. You can post the link to the question here. – Krishna Mar 22 '11 at 07:50
52

I had the same problem. How to fix : Open up image with Preview -> File > Export > Format change to PNG and you are done !!

Dorald
  • 724
  • 7
  • 12
10

There is no issues with image or Xcode. The issue, which creating that image from photoshop, is whether that image is interlaced or not interlaced. While saving your image in photoshop you will get one option for that.

Check out this link for more info:

Build app with Xcode 4 - it always show some error about PNG image

not interlaced: You should use image which is not interlaced. This is the original png image.

interlaced: This option is suitable for the image which are getting downloaded from web. Specifically saying, this is used when you require to reduce image load time. What this option internally does is, it will create a .png file but with lower clarity and lower dpi like a normal jpeg image. That's why such images are having property that it is jpeg image.

Hope this will help you all.

Enjoy Coding :)

Community
  • 1
  • 1
Mrunal
  • 13,982
  • 6
  • 52
  • 96
10

I got this error when I moved images around in the project's folder, to an "Images" folder.

Turns out my "Copy Resources" build phase contained the steps both to copy the files from their new, correct folder - and from the previous folder where they were stored. Removing the outdated build steps fixed the errors.

Danra
  • 9,546
  • 5
  • 59
  • 117
6

Another reason pngcrush considers PNG files to not really be PNG files is if you accidentally export them with layers intact. If you inspect the file in Finder, look around the More Info area (Dimensions, Color Space, etc.) for an item called "Layers"

It might say something like:

Layer 68, Title Banner, Group 26

This happens when designers sometimes Save As PNG instead of exporting for web/mobile. And it completely destroys libpng (and thus pngcrush).

The fix is to properly export the PNG, or open the PNG yourself and re-export it as a "flat" PNG.

Eric G
  • 1,429
  • 18
  • 26
  • 1
    Note: this can also be caused by PSD files that are saved with a PNG extension, but are really PSD files. This happens fairly often too, no matter how good the designer. Late nights are late nights. :) – Eric G Apr 16 '13 at 21:20
6

This can be caused by incompatible PNG file format. You will need the "Color profile" for your png file to make it work in Xcode.

First off, check the info for your file.

enter image description here

While this is a valid PNG file, this is NOT the format that Xcode can take. You will need the following PNG format:

enter image description here

To convert your PNG file to a format that Xcode can take. You can use Preview to export the file.

ABCD
  • 7,914
  • 9
  • 54
  • 90
  • I had edited some of the graphical assets on Linux using gwenview and GIMP, saved as PNG then hit this error/ For me THIS answer and solution is perfect. Clearly the original assets by our UI team were done on a Mac and were (obviously) perfect as far as Xcode was concerned. – KayCee Aug 03 '17 at 12:36
  • my Map Tile overlays were done on a Mac, without the Alpha Channel ( hence no sRGB ) but still fails in my project, yet work perfectly in others. – aremvee May 18 '18 at 07:13
3

Had this issue as well. The PNG existed and wasn't corrupt.

Solved it by:

  1. R-click the image in xcode, select "Delete"
  2. Remove reference only (don't actually trash the file)
  3. Drag n' drop it back into xcode (in-place) making sure you select the correct targets
capikaw
  • 12,232
  • 2
  • 43
  • 46
2

I had this error and it was actually totally unrelated to the png's it was erroring on. The actual problem was I had two files with the same name in my project (I had drag'n'dropped a newer version of a 3rd party class assuming it would replace the older version).

I removed the reference to the duplicate file and that solved the build errors.

Rembrandt Q. Einstein
  • 1,101
  • 10
  • 23
2

I had this problem and found there was a problem with the png. I remade it and worked fine.

Derek Howe
  • 29
  • 1
2

I had the same problem. Even though the file extension may be png the file may still be something else. And 'get info' shows what ever the file extension is I think. Open up the file in preview and go to tools -> show inspector -> File tab. Here you should be able to see the actual file type.

NSRover
  • 932
  • 1
  • 12
  • 29
  • Have you got the reason behind this issue? We have got images created from Adobe Photoshop, saved as .png. But those images are being displayed as JPEG in that menu, which you have suggested. Not getting why? – Mrunal Apr 16 '12 at 13:37
  • I think if that menu shows them as JPEG then they must be JPEG. Maybe there was some mistake while saving them. Did you try doing this with some PNG downloaded from web. – NSRover Apr 20 '12 at 08:47
  • Every once in a while I save a .psd with .png extension... Damn Photoshop defaults! – Nicolas Miari Jun 18 '12 at 19:50
0

Problem Solved

I got the same problem couple of time in development but today i found that there are two solutions and their possibilities, here is this

Problem Solved#1: If you Create or your designer create the design which they saved the pnd from adobe illustrator then its got the problem if you create by yourself just copy all the AI artwork to the photoshop or if your designer create it then just tell them to import the illustrator format to the photoshop and send the pnd.

Problem Solved#2: select the image right click the image->get Info and check that it is in correct .png format or not if its not then just edit .png extension.

Just Enjoy.

Appz Venture
  • 939
  • 1
  • 13
  • 28
0

I get the same error when I tried to copy my project folder and run the project. The project in the original folder didn't have that problem.

Deleting the copy and making a new copy of the folder solved my problem.

alpere
  • 1,079
  • 17
  • 26
0

Error:

While reading /Volumes/Mac OS/RDC/Workpot/RestApp/RestApp/default1024_768.png pngcrush caught libpng error: Not a PNG file..

Solution:

  1. I opened "default1024_768" file in PaintBrush tool and saveAs PNG file with same name.
  2. Replaced the Icon file in Xcode project --> Clean --> Build.

That's All its work like charm

Hope this will help someone.

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
-3

I have this bug quite often. if you 100% sure that your png is there and is correct then just simply recompile the project, if does not work - recompile again and again, and sometimes it will start working ;-) that's a bug in Xcode that was there for long time (since Xcode3).