ios Xcode 构建中不包含应用程序图标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46109835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:25:19  来源:igfitidea点击:

App Icons not included in build from Xcode

iosxcode

提问by Sahil Kapoor

I can't see iOS AppIcon when installing build from latest Xcode Beta 6. What could be the possible error?

从最新的 Xcode Beta 6 安装构建时,我看不到 iOS AppIcon。可能的错误是什么?

I have included required icons sizes including 1024x1024.

我已经包含了所需的图标大小,包括 1024x1024。

采纳答案by Duncan Babbage

You are not alone.

你不是一个人。

In my project, I found that a previous AppIcon resource that was working fine no longer resulted in an app icon being rendered. A range of experimentation found the following:

在我的项目中,我发现以前运行良好的 AppIcon 资源不再导致呈现应用程序图标。一系列的实验发现如下:

  • An AppIcon resource copied in from another project where the AppIcon worked, resulted in the AppIcon working in this project, suggesting there was something wrong with the specific original AppIcon resource that wasn't working.
  • Copying the image files from the non-working to the working AppIcon asset resulted in the working one now failing also.
  • Creating a new AppIcon resource, and inserting the original app icon images likewise led to a blank app icon.
  • 从 AppIcon 工作的另一个项目中复制的 AppIcon 资源导致 AppIcon 在该项目中工作,这表明特定的原始 AppIcon 资源存在问题,无法工作。
  • 将图像文件从非工作的 AppIcon 资产复制到工作的 AppIcon 资产导致工作的资产现在也失败了。
  • 创建一个新的 AppIcon 资源,并插入原始的应用程序图标图像同样会导致一个空白的应用程序图标。

Combined together, the points to this stage suggested perhaps there was something wrong with the image files themselves. I therefore tried various steps to resolve this:

综合起来,这个阶段的要点表明图像文件本身可能有问题。因此,我尝试了各种步骤来解决这个问题:

  • Re-exporting all the icon sizes with my usual pre-processing app Prepo. Ensured that my source image did not contain transparency. Inserting those re-created icon images still resulted in a blank app icon.
  • Re-creating all the icon sizes with a different process, via Sketch, and inserting those icon images into the same AppIcon resource resulted in the app icon working.
  • Creating a new AppIcon resource, and inserting the Sketch-created images resulted in the app icon still working.
  • 使用我常用的预处理应用程序 Prepo 重新导出所有图标大小。确保我的源图像不包含透明度。插入那些重新创建的图标图像仍然会导致一个空白的应用程序图标。
  • 通过 Sketch 使用不同的过程重新创建所有图标大小,并将这些图标图像插入到相同的 AppIcon 资源中,从而使应用程序图标正常工作。
  • 创建一个新的 AppIcon 资源,并插入 Sketch 创建的图像导致应用程序图标仍然有效。

All of the above suggests that there is something in Xcode 9 which rejects or fails to use previously working app icon images, and that some processes to create app icons that previously were fine produce images that Xcode 9 cannot use. Perhaps there is something within the png specification which is a valid png, but not an acceptable app icon to Xcode 9. The most obvious thought is that app icons with transparency might be rejected, but I do not believe the icon images I was using contained transparency and I tried to eliminate this in my testing above.

以上所有内容都表明 Xcode 9 中存在一些拒绝或无法使用以前工作的应用程序图标图像的东西,并且一些创建以前很好的应用程序图标的过程会产生 Xcode 9 无法使用的图像。也许 png 规范中有一些东西是有效的 png,但不是 Xcode 9 可接受的应用程序图标。最明显的想法是具有透明度的应用程序图标可能会被拒绝,但我不相信我使用的图标图像包含透明度,我试图在上面的测试中消除这一点。



A completely separate cause that has been reported for some users is related to CocoaPods integration. See discussion with possible temporary fix hereand a pull request that has been created for Cocoapodsthat theoretically addresses this issue. I say theoretically addresses because I've tried implementing both of these solutions, and neither of them resolved the issue on the project where I've encountered it.

一些用户报告的完全独立的原因与 CocoaPods 集成有关。请参阅此处讨论可能的临时修复以及为 Cocoapods 创建的从理论上解决此问题的拉取请求。我说理论上的地址是因为我已经尝试实施这两种解决方案,但它们都没有解决我遇到的项目中的问题。

回答by Damo

For clarity, make sure that the color profile is set to: sRGB IEC61966-2.1. My icons had no color profile before I stumbled across this issue.

为清楚起见,请确保将颜色配置文件设置为:sRGB IEC61966-2.1。在我偶然发现这个问题之前,我的图标没有颜色配置文件。

I'm sure other color profiles must work but I haven't done the testing to be sure.

我确定其他颜色配置文件必须有效,但我还没有做过测试来确定。

This can be done in preview by:

这可以通过以下方式在预览中完成:

  1. Tools → Assign Profile
  1. 工具 → 分配配置文件

Assign Profile1

分配配置文件 1

  1. Select sRGB IEC61966-2.1
  1. 选择sRGB IEC61966-2.1

Assign Profile2

分配配置文件 2

When you do a Get Info on the icons it should now say the correct Color Profile.

当您在图标上执行获取信息时,它现在应该显示正确的颜色配置文件。

Example of working / non working Get Info on two images

工作/非工作示例获取两个图像的信息

回答by Nikunj Joshi

After trying various solutions like "Asigning color profile (sRGB IEC61966-2.1) to icons"and "CocoaPods solution"stated above, or "Changing App Icon Source name to different asset name in proect setting", I found one very basic solution as follow:

在尝试了上述“将颜色配置文件 (sRGB IEC61966-2.1) 分配给图标”“CocoaPods 解决方案”“在项目设置中将应用程序图标源名称更改为不同的资产名称”等各种解决方案后,我找到了一个非常基本的解决方案,如下所示:

  1. Clear your project.
  2. Clear derived data at (~/Library/Developer/Xcode/DerivedData/)
  3. Go to "Project -> Build Phase"
  4. Find "Copy Bundle Resources and drag it as the last item of the list".
  5. Uninstall application if it is already there, and run project.
  1. 清除您的项目。
  2. 清除 ( ~/Library/Developer/Xcode/DerivedData/)处的派生数据
  3. 转到“项目-> 构建阶段”
  4. 找到“复制捆绑资源并将其作为列表的最后一项”
  5. 如果应用程序已经存在,请卸载它,然后运行项目。

Find screenshot for better understanding.

查找屏幕截图以更好地理解。

Before

enter image description here

在此处输入图片说明

After

enter image description here

在此处输入图片说明

Note: You can check, what is creating problem for app-icon in your project by simply changing position of "Copy Bundle Resources" to upward direction.

注意:您可以通过简单地将“复制捆绑资源”的位置更改为向上方向来检查项目中应用程序图标的问题。

回答by grwilde

I had the same problem with my App icons. They displayed on some devices but not on others. I looked further into the problem and found that not all of my icons had been flattened and all had an incorrect color space (Adobe RGB). I flattened all icons and converted to SRGB color space, then replaced the existing icons. All icons show perfectly now.

我的应用程序图标也有同样的问题。它们显示在某些设备上,但不显示在其他设备上。我进一步研究了这个问题,发现并不是所有的图标都被扁平化了,而且所有的颜色空间(Adobe RGB)都不正确。我将所有图标展平并转换为 SRGB 色彩空间,然后替换现有图标。现在所有图标都完美显示。

回答by John Guy

Another Simple Fix once discovered:

曾经发现的另一个简单修复:

I had the same issue with XCode 9.0, a project that worked perfectly well under XCode 8 and iOS 10 suddenly loses it's icons (only on iPads) when I upgraded the solution.

我在 XCode 9.0 上遇到了同样的问题,当我升级解决方案时,一个在 XCode 8 和 iOS 10 下运行良好的项目突然丢失了它的图标(仅在 iPad 上)。

Tore my hair out, did the sRGB thing, did the Transparency thing.

撕掉我的头发,做了 sRGB 的事情,做了透明的事情。

Turns out I still had the following empty entry in my targets info.plist file

结果我的目标 info.plist 文件中仍然有以下空条目

CFBundleIcons~ipad

CFBundleIcons~ipad

I'd long ago moved to specifying this in the target build settings.

我很久以前就开始在目标构建设置中指定它。

The solution was to simpy remove this entry from the info.plist file (clicked the helpfull little "-" button. Rebuilt and tested and everything was perfect once more.

解决方案是简单地从 info.plist 文件中删除此条目(单击有用的小“-”按钮。重建和测试,一切再次完美。

回答by Matthew Barker

Edit:This needs to fire in the middle of gym, which I don't know how to do. Running the bug fix as soon as the archive appears in the folder will do the trick. If someone can help improve this, please let me know!

编辑:这需要在中间触发gym,我不知道该怎么做。一旦存档出现在文件夹中,就立即运行错误修复程序即可解决问题。如果有人可以帮助改善这一点,请告诉我!

I ran into this problem using Fastlane, and I wrote a shell script that I run as a lane to solve the problem. The fix itself is code from user stubyte in this thread.

我在使用 Fastlane 时遇到了这个问题,我写了一个 shell 脚本,作为一个通道运行来解决这个问题。修复本身是来自该线程中用户 stubyte 的代码。

Here is my script for archive_fix.sh:

这是我的脚本archive_fix.sh

#!/bin/bash

# navigate to latest archive created
cd ~/Library/Developer/Xcode/Archives
foo=$(ls -t | head -n1) && cd $foo
line=$(ls -t | head -n1) && cd "$line"

 # bug fix
find Products/ -name Info.plist -print0 | xargs -0n1 plutil -replace BuildMachineOSBuild -string 16A323

Inside my Fastfile, I ran:

在我的 Fastfile 中,我运行了:

sh("./archive_fix.sh")

回答by Aakash Aggarwal

Problem:

问题:

1. App icon not appearing on iOS 11 or Xcode 9.

1. 应用图标未出现在 iOS 11 或 Xcode 9 上。

2. App icon visible on iPhone but not in iPad.

2. 应用程序图标在 iPhone 上可见,但在 iPad 上不可见。

Solution that worked for me:

对我有用的解决方案:

The issue seems to be with the build process for Xcode 9 and iOS 11. In the past, Apple has been using ~iPad extension to differentiate between the assets for iPhone and iPad.

问题似乎与 Xcode 9 和 iOS 11 的构建过程有关。过去,Apple 一直使用 ~iPad 扩展来区分 iPhone 和 iPad 的资产。

The info.plist has a dictionary with the key “CFBundleIcons~ipad” which has no items (as it appears in Xcode 9), which is causing the bundle to GET the images from the info.plist file instead of images.xcassets, thus the app icon on Xcode 9 is not appearing.

info.plist 有一个字典,键为“CFBundleIcons~ipad”,它没有项目(如 Xcode 9 中所示),这导致包从 info.plist 文件而不是 images.xcassets 获取图像,因此Xcode 9 上的应用程序图标没有出现。

Deleting this key from .plistfile worked for my build, while the others did'nt.

从 .plist文件中删除此密钥对我的构建有效,而其他人则没有。

Deleting "CFBundleIcons~ipad" key from .plist

从 .plist 中删除“CFBundleIcons~ipad”键

回答by ack

I spent a whole day wasting time on this. I checked my png files to ensure no transparency, to ensure correct RGB settings, I also changed the podfile as discussed here. Nothing worked. The upgrade to Xcode 9/iOS 11 seemed to break/change something as icons were previously showing for me for the same app.

我花了一整天的时间在这上面浪费时间。我检查了我的PNG文件,以确保没有透明度,以确保正确的RGB设置,我也改变了podfile所讨论这里。没有任何效果。升级到 Xcode 9/iOS 11 似乎破坏/改变了一些东西,因为之前为我显示的同一个应用程序的图标。

Anyway, what fixed it for me was to change the name of the iOS App Icon in the Assets.xcassets (Default = AppIcon), and to also change the 'Asset Catalog App Icon Set Name' in the Build Settings to align with the new name.

无论如何,为我修复的是在 Assets.xcassets(默认 = AppIcon)中更改 iOS 应用程序图标的名称,并在构建设置中更改“资产目录应用程序图标集名称”以与新的姓名。

Strangly, after I got this to work, I updated all my images in AppIcon within Assets.xcassets and I got a blank image again! Repeated above steps and problem solved for second time.

奇怪的是,在我开始工作后,我在 Assets.xcassets 中更新了 AppIcon 中的所有图像,我再次得到了一个空白图像!重复以上步骤,问题第二次解决。

回答by Chris Marstall

TL;DR: create a "Copy Bundle Resources" Build Phase

TL;DR:创建“复制捆绑资源”构建阶段

After a day and a half trying pretty much every solution on this and other threads, I found a very different fix that worked for me. Looking at app package within my build folder, I noticed that the App Icon png files were not being copied over into it. I created a blank app from scratch, added an app icon, and in that blank app it did copy the icon file over. So what gives?

在一天半的时间里尝试了这个和其他线程上的几乎所有解决方案后,我发现了一个对我有用的非常不同的修复程序。查看我的构建文件夹中的应用程序包,我注意到应用程序图标 png 文件没有被复制到其中。我从头开始创建了一个空白应用程序,添加了一个应用程序图标,并在该空白应用程序中复制了图标文件。那么什么给呢?

The blank app had a "Copy bundle resources" build phase that copied the Assets.xcassets package over. Mine didn't. So I created one, added my Images.xcassets, and presto change-o, my archive got validated. NB I am pretty sure I never had that build phase before, yet I was able to submit a build just a month ago ...

空白应用程序有一个“复制捆绑资源”构建阶段,它复制了 Assets.xcassets 包。我的没有。所以我创建了一个,添加了我的 Images.xcassets,然后快速更改,我的存档得到了验证。注意,我很确定我以前从未有过构建阶段,但就在一个月前我才能够提交构建......

回答by zeeawan

In my case none these solutions worked.

在我的情况下,这些解决方案都不起作用。

My icons were not being shown cause they were NOT IN CORRECT SIZES. Once I resize them correctly then my issue got resolved.

我的图标没有显示,因为它们的尺寸不正确。一旦我正确调整了它们的大小,我的问题就得到了解决。