skip to Main Content

I am tearing my hair out trying to set up a custom icon for my OS X app. I have created all of the image files needed:

mondrian_128x128.png
[email protected]
mondrian_16x16.png
[email protected]
mondrian_256x256.png
[email protected]
mondrian_32x32.png
[email protected]
mondrian_512x512.png
[email protected]

I have dragged each image into the appropriate well in my AppIcon xcassets area, and all ten images now appear there. (The ones larger than 32×32@2x all get displayed at the same size as the 32×32@2x one in Xcode, but perhaps that is as it should be; I am guessing Xcode does that to conserve screen real estate, since displaying a 1024×1024 image would take up the whole window.)

When I inspect these images in Xcode, by clicking on each well, it shows information in the inspector area that appears to be good – the correct name, size, scale, etc. Similarly, the .json file inside the .xcassets looks good:

{
  "images" : [
    {
      "size" : "16x16",
      "idiom" : "mac",
      "filename" : "mondrian_16x16.png",
      "scale" : "1x"
    },
    {
      "size" : "16x16",
      "idiom" : "mac",
      "filename" : "[email protected]",
      "scale" : "2x"
    },
    {
      "size" : "32x32",
      "idiom" : "mac",
      "filename" : "mondrian_32x32.png",
      "scale" : "1x"
    },
    {
      "size" : "32x32",
      "idiom" : "mac",
      "filename" : "[email protected]",
      "scale" : "2x"
    },
    {
      "size" : "128x128",
      "idiom" : "mac",
      "filename" : "mondrian_128x128.png",
      "scale" : "1x"
    },
    {
      "size" : "128x128",
      "idiom" : "mac",
      "filename" : "[email protected]",
      "scale" : "2x"
    },
    {
      "size" : "256x256",
      "idiom" : "mac",
      "filename" : "mondrian_256x256.png",
      "scale" : "1x"
    },
    {
      "size" : "256x256",
      "idiom" : "mac",
      "filename" : "[email protected]",
      "scale" : "2x"
    },
    {
      "size" : "512x512",
      "idiom" : "mac",
      "filename" : "mondrian_512x512.png",
      "scale" : "1x"
    },
    {
      "size" : "512x512",
      "idiom" : "mac",
      "filename" : "[email protected]",
      "scale" : "2x"
    }
  ],
  "info" : {
    "version" : 1,
    "author" : "xcode"
  }
}

When I build my app, however, things seem to be messed up. No build warnings or errors appear, but the built product does not have any but the smallest sizes. Specifically: AppIcon.icns, which is generated by Xcode, seems to have only the 16×16 and 16×16@2x images. I can see this by doing a QuickView of it in the Finder (as Apple recommends), or by opening it in Preview. Furthermore, the app itself, when I select it in the Finder, shows a blurry icon that is clearly scaled up from the small icon. And when I use NSApplicationIcon in an NSImageView in a panel, the icon displayed is tiny. The larger sizes have clearly not been copied over.

I’ve spent all morning reading about .xcassets on the web, watching a YouTube video on how to assemble them, and (of course) looking at Apple’s rather unhelpful documentation. I can’t for the life of me figure out what I’m doing wrong. Any ideas?

UPDATE:

I’m now experimenting with trying to get iconutil to make the ICNS, in the hopes of understanding why Xcode can’t do it properly. I copied my AppIcon.appiconset to my Desktop and tried “iconutil -c icns AppIcon.appiconset”. It said “AppIcon.appiconset:error: Invalid Iconset.”. I changed the name to “AppIcon.iconset” in case that was an issue, and it changed its error to “AppIcon.iconset:error: Failed to generate ICNS.” It occurred to me that maybe the images need to have the same name as the name of the .iconset, so I changed them all from starting with “mondrian” to starting with “AppIcon”. Still getting “AppIcon.iconset:error: Failed to generate ICNS.” Sure would be nice if iconutil printed out more helpful error messages.

I also just opened all of the image files in GraphicConverter, added an alpha channel, and saved them back out, thinking that perhaps an alpha channel was required (although I have seen no mention of that anywhere – but most apps do have alpha in their icon, so…). Again, no change: “AppIcon.iconset:error: Failed to generate ICNS.”. Aargh.

UPDATE 2:
It now works. I’m not sure why. I added the modified images (alpha channel added, saved in GraphicConverter instead of from Photoshop Elements) that were in my experimental .iconset on my Desktop back into the AppIcon in the .xcassets of my Xcode project, cleaned and built, and it is now all good. iconutil still refuses to compile it to an ICNS, but Xcode can now do it. I have no idea why. Maybe something about the state of my project was corrupted, or maybe alpha was needed, or maybe GraphicConverter saves PNG files in a way that Xcode likes better than Photoshop Elements’ format. Mysteries abound. Anyway, perhaps this record will be helpful to someone else in a similar situation.

3

Answers


  1. I was experiencing the same problem. “Clean Build”, “Clean Build Folder” (⎇⇧⌘K) and the other suggestions did not improve matters, but they did point me in the right direction.

    I had followed this guide to create the iconset but it may be out of date and/or I made a mistake and fouled things up.

    Before starting the following steps which seem to have resolved the issue I was able to view all the correct icons inside my app package.
    View Package > Contents/Resources/*.icns

    To reset everything I did the following:

    Remove everything icon related from the project:

    1. Use the Project Navigator to remove from the project the assetcatalog and iconset folders. I believe the icns folder was created by the command line icon utility and was not needed.
    2. Manually remove the associated folders from the project folder.
    3. Restart Xcode for good measure.

    Add the icons again:

    Since I still had all the correct icons in a iconset folder on the file system, I did the following to add the icons to the project:

    1. In the Project Navigator right click the project folder and select “New File…”

    2. Select OS X > Resource > Asset Catalog to create a new asset catalog folder in the project folder. Trying to point this to the existing iconset folder just seemed to complicate matters.

    3. Click on the newly created assets folder in the Project Navigator and then right click on the new icon place holder in the center of the Xcode interface. Select “New Mac OS Icon” from the pop up menu. You should now see all the empty wells for the different icon sizes.

    4. Right click again and “Import…” from your existing iconset folder(this step revealed that I had some extra .pngs Xcode didn’t know what to do with). Drag and drop from one container to the other until all are filled and then remove the empty icon holder. Right clicking also reveals a useful “Get Asset Catalog” link at the bottom of the menu that is not easy to find via the normal help option (it’s not under the main Editor menu at the top of the screen either).

    5. Clean Build, Clean Folder and Build.

    Login or Signup to reply.
  2. I found that if i re-saved the images using Preview.app, ensuring the right canvas size and ppi for each image, that I was able to get all 10 representations to show up in the resulting icns file.

    My guess is that Photoshop or Photoshop elements is injecting extra junk into the files that the iconutil/xcode doesn’t like. In fact post-save, every single file was substantially smaller (16×16 1x went from 374kb to 1kb).

    Login or Signup to reply.
  3. In addition to the solutions above, saving the images using “sRgb” color profile solved the issue for me. it can be done by preview or photoshop or other preferred editor.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search