How to manually create icns files using iconutil?

2020-01-26 12:34发布

When I'm validating my app I get this error:

the application bundle does not contain an icon in ICNS format, containing both a 512x512 and a 512x512@2x image.

I use to make the icns icons with Img2icns app and until today it always worked properly. But now I'm getting that error and there's no way to make it work. I tried to put two PNG files together (512x512 and 1024x1024) in Img2icns but I always get that error. I also tried to follow the instructions in Apple's OS X Human Interface Guideline but when I try to make the icon sets I get this terminal error:

-bash: syntax error near unexpected token 'newline'

I am not very good with terminal commands so maybe I'm doing something wrong. I wrote:

iconutil -c icns </Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset>

If anyone could help it would be very much appreciated. Thanks, Massy.

18条回答
老娘就宠你
2楼-- · 2020-01-26 12:52

Dead simple .png

查看更多
祖国的老花朵
3楼-- · 2020-01-26 12:52

There are 2 tasks:
- create 10 correct icns files
- get your Xcode project to use them correctly

As I had hour long problems with both of these tasks, and also do not like when I don't 'see' what is going on, here a path for the cautious ones:

Create 10 correct icns files:
I used the script above from Henry: It still works for HighSierra and Xcode 9.2, including the 'c' command.
The icns file I got, appeared as only one icon size in Finder/Quicklook and in Preview showed only 8 of 10 sizes.
So I used terminal, went with cd to my folder and used the command: iconutil -c iconset (icns filename) on the just created icns file to revert the icns file back to an iconset folder, and - lo & behold - I could see my newly created 10 icon files. Using Quick look on the iconset folder (and using full screen mode to be able to zoom through them with the slider), I could check that all sizes are actually looking very well.

As an aside: they looked better than my resizing attempts with PSE, most likely because I did not take the time to play with all the resizing options in PSE. If you do use PSE, make sure your png files are saved without colour profile. Also, confessing my ignorance, for me a 256x256@2 file is the same as a 512x512 file - both in 72dpi. Trying to follow the 144 dpi comments above did not work for me.

Get your Xcode project to use them correctly:
First I deleted all my fruitless attempts within Xcode and committed a clean version to the git repository (what would have been clever, would have been to commit a clean version first - before I frantically started the icon addition odyssee).
I also made sure that in the info.plist file there is no pointer linked to the 'icon file' entry and that in my General project settings I had chosen AppIcon for App Icons.
Then I added an assets.asset catalog and within the assets catalog a new 'AppIcons and Launch Images' AppIcon Folder for OS.
Then I copied (drag and drop with option pressed) from the iconset folder each png picture file into the respective AppIcon Spaceholder. So again, I could see what is happening. Xcode did convert that into icns files, or maybe - as my iconset folder derived from an icns folder - the file formats were accepted.

Then archive and validate and there will be no errors upon uploading or validating.

查看更多
戒情不戒烟
4楼-- · 2020-01-26 12:53

Hello, for my needs I made a droplet that works in drag and drop icons alone or icons to search in a folder (I limited to folders as the searches on Volumes of all the icons can take a lot of time ). So in drag and drop you can drop folders or application, anything that can contain an icon. The iconset created bears the name of the original icon, it is placed in a directory "/ aaaicones" and the path of the icon. Example in the folder "/ aaaicones if you submit xcode.app you will find "/aaaicones/Applications/xcode.app/access.iconset" and /aaaicones/Applications/xcode.app/access.icns (the recreated icon) there will be a text file where it is traced the full path of the icons , And the path to the corresponding iconset example "/Applications/xcode.app/Contents/Applications/Instruments.app/Contents/Frameworks/InstrumentsPlugIn.framework/Versions/A/Resources/access.icns" "/aaaicones/Applications/xcode.app/access.iconset" in the example taken (xcode) this can create a folder at the end (with all icons and iconset) of 214 MB in size. If you treat an icon alone, it will be placed in the directory "/ aaaicones / aIconeseule /" and its original path, example /aaaicones/aIconeseule/Mac Elcapitan/.VolumeIcon.icns and /aaaicones/aIconeseule/Mac Elcapitan /.VolumeIcon.iconset with /aaaicones/aIconeseule/Mac Elcapitan/aalisticones.txt The droplet is below

on open draggedItems
    set input to draggedItems
    set fich to draggedItems


    set media to {}

    set theInfo to {}

    set n to "0"
    repeat with currentItem in draggedItems
        set dirchoisi to POSIX path of fich
        if ".icns" is not in dirchoisi then
            if "Volumes" is not in dirchoisi then

                set origi to do shell script "echo   /aaaicones" & dirchoisi
                set fich to do shell script "echo " & fich & " | xxd -p -c 100000 | sed 's#3a#2f#g' | xxd -r -p | sed 's#" & dirchoisi & "#" & "/aaaicones" & dirchoisi & "#g' | xxd -p -c 100000 | sed 's#2f#3a#g' | xxd -r -p"
                tell application "Finder"
                    if exists (folder fich) then
                        set nn to "0"
                        repeat with nn from 1 to 5
                            set origi to do shell script "echo  " & origi & "/" & " | sed 's#//#" & nn & "/" & "#'"
                            set fich to do shell script "echo " & fich & " | sed 's#:aaaicones*.*#" & origi & "#'" & " | xxd -p -c 100000 | sed 's#2f#3a#g' | xxd -r -p"

                            if not (exists folder (fich as Unicode text)) then
                                try
                                    set origi to do shell script "echo  " & origi
                                    exit repeat
                                end try
                            end if
                        end repeat
                    end if
                end tell
                tell application "Finder"
                    if not (exists folder (fich as Unicode text)) then
                        do shell script "mkdir -p -m 0777 " & quoted form of origi
                    end if
                end tell
                try
                    set theInfo to do shell script "find " & (quoted form of dirchoisi) & " -name *.icns "
                end try




                set AppleScript's text item delimiters to return

                set theList to text items of theInfo

                set AppleScript's text item delimiters to ""

                set n to count theList
                repeat with i from 1 to n
                    if "Volumes" is not in item i of theList then
                        set end of media to item i of theList
                    end if
                end repeat
                set n to count media
                set cheminicns to do shell script " > " & quoted form of (origi & "aalisticones.txt") & " |  chmod 777 " & quoted form of (origi & "aalisticones.txt")
                set cheminicns to do shell script "ls " & quoted form of (origi & "aalisticones.txt")

                tell application "Finder"
                    set letext to (POSIX file cheminicns as alias)
                    set label index of letext to 2
                end tell



                repeat with i from 1 to n

                    set hdd to item i of media
                    try

                        set input to do shell script "echo   " & hdd & " | sed 's#//#/#g; s#(#\\(#g;s#)#\\)#g' "
                        do shell script "echo   " & quoted form of input & " >>" & quoted form of cheminicns
                        set png to do shell script "echo " & quoted form of input & " | sed 's#.*/##' "

                        do shell script "cp -f " & quoted form of input & " " & quoted form of origi
                        set input to do shell script "iconutil -c iconset  " & quoted form of (origi & png)
                        do shell script "echo   " & quoted form of (origi & png) & " | sed 's#.icns#.iconset#' >>" & quoted form of cheminicns
                    end try
                end repeat
                tell application "Finder"
                    if exists (folder fich) then
                        open fich
                    end if
                end tell

            end if
        else

            set input to do shell script "echo   " & dirchoisi & " | sed 's#//#/#g; s#(#\\(#g;s#)#\\)#g' "
            set png to do shell script "echo " & quoted form of input & " | sed 's#.*/##' "
            set origi to do shell script "echo " & quoted form of ("/aaaicones/aIconeseule/" & input) & " | sed 's#/Volumes/##; s#" & quoted form of png & "##'"
            do shell script "mkdir -p -m 0777 " & quoted form of origi
            do shell script "echo   " & quoted form of input & " >>" & quoted form of origi & "aalisticones.txt"

            do shell script "cp -f " & quoted form of input & " " & quoted form of origi
            set input to do shell script "iconutil -c iconset  " & quoted form of (origi & png)
            do shell script "echo   " & quoted form of (origi & png) & " >>" & quoted form of origi & "aalisticones.txt"
        end if
    end repeat
end open
查看更多
【Aperson】
5楼-- · 2020-01-26 12:54

When I'm validating my app I get this error:

the application bundle does not contain an icon in ICNS format, containing both a 512x512 and a 512x512@2x image.

I am not very good with terminal command and so maybe I'm doing something wrong. I wrote:

iconutil -c icns </Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset>

For one thing, as I mentioned in a comment on Anne's answer, you probably don't need to use iconutil. You should be able to just add the iconset to your project and let Xcode convert it for you as part of the build.

Either way, this may be your problem:

I tryed to put two PNG files togheter (512x512 and 1024x1024) … but I always get the error.

There is no 1024 by 1024 point size. The 1024 by 1024 pixel element (which was 1024 points before Mountain Lion) is now used for 512 by 512 points @2x.

Your PNG file must be named appropriately: icon_512x512@2x.png

查看更多
姐就是有狂的资本
6楼-- · 2020-01-26 12:55

These commands (entered in Terminal) worked for me to convert an old icns file to the new format:

cd Folder_With_Icns_File
iconutil -c iconset Your_Icon_Name.icns 
rm Your_Icon_Name.icns 
iconutil -c icns Your_Icon_Name.iconset
rm -R Your_Icon_Name.iconset

Update

The -c parameter to iconutil is no longer supported. Use --convert instead:

cd Folder_With_Icns_File
iconutil --convert iconset Your_Icon_Name.icns 
rm Your_Icon_Name.icns 
iconutil --convert icns Your_Icon_Name.iconset
rm -R Your_Icon_Name.iconset
查看更多
姐就是有狂的资本
7楼-- · 2020-01-26 12:56

Additional comment, when you create .icns file, you need to rename all the pic files with prefix "icon_", otherwise, iconutil will fail with error message: ".iconset:error: Failed to generate ICNS." which is not informative at all.

查看更多
登录 后发表回答