xcode 减少 iOS 应用程序文件大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27321409/
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-09-15 06:19:29  来源:igfitidea点击:

Reducing iOS App file size

iosxcodeswiftios8.1application-size

提问by Michael

I have made a very simple iPhone app with Xcode 6.1 and swift. I am really new to ios developing and ran into an app which in the end is 134 mb! of course this is not acceptable.

我用 Xcode 6.1 和 swift 制作了一个非常简单的 iPhone 应用程序。我真的是 ios 开发的新手,遇到了一个最终是 134 mb 的应用程序!这当然是不能接受的。

I have background images for all screen sizes which add up to 20 mb. and thats it! I am storing those images in xcassets, as thats the preferred way I guess.

我有所有屏幕尺寸的背景图像,加起来最多 20 mb。就是这样!我将这些图像存储在 xcassets 中,因为这是我猜的首选方式。

the app shouldnt have more than 25 mbs, I think.

我认为该应用程序不应超过 25 mbs。

I figured out that I had some references doubled in my project. I removed these and still my .app file is 89 mbs!

我发现我的项目中有一些参考文献翻了一番。我删除了这些,但我的 .app 文件仍然是 89 mbs!

What am I doing wrong? I read several threads on this, but nothing really helped!

我究竟做错了什么?我阅读了几个关于此的主题,但没有任何帮助!

What I did until now:

到目前为止我所做的:

- reduce the size of all pngs
- disable the compress PNG option, as it seems to make the PNGs bigger (lol)
- configured the build settings to run the fastest and smallest build
- Strip Debug Symbols During Copy build setting to Yes (COPY_PHASE_STRIP = YES)

edit1: Apparenty Xcode does something weird with my pngs. Some of those pictures, that are 2 mb originally, are more than 10mb in the .app-file. What does xcode do there ?

编辑 1:显然 Xcode 对我的 png 做了一些奇怪的事情。其中一些图片,最初是 2 mb,在 .app 文件中超过 10 mb。xcode 在那里做什么?

回答by David Berger

It is actually not surprising that the Apple recompressed files are bigger. They are optimized for fast load not small size. If you do not care about size over speed, defiantly do turn off the compression. Even if you do care about speed you can do better than Apple.

Apple 重新压缩的文件更大实际上并不奇怪。它们针对快速加载而不是小尺寸进行了优化。如果您不在乎大小而不是速度,请务必关闭压缩。即使您确实关心速度,您也可以比 Apple 做得更好。

https://imageoptim.com/xcode.html

https://imageoptim.com/xcode.html

So yes, turn off the PNG compression. The first thing I would do is build the ipa. An ipa is actually a zip file so build the ipa, copy it to a folder on your mac, rename the file with a .zip extension and double click on it. This will expanded it. Find the app in the Payload folder and right mouse click on it and choose show package contents. You will see all the assets. Sort by size. I am guessing you have overly large images. At that size my guess is that the extra size is likely to be caused almost entirely by the PNG files.

所以是的,关闭 PNG 压缩。我要做的第一件事就是构建ipa。ipa 实际上是一个 zip 文件,因此请构建 ipa,将其复制到 Mac 上的文件夹中,使用 .zip 扩展名重命名文件并双击它。这将扩大它。在 Payload 文件夹中找到该应用程序并右键单击它并选择显示包内容。您将看到所有资产。按大小排序。我猜你有过大的图像。在这个大小下,我的猜测是额外的大小可能几乎完全是由 PNG 文件造成的。

Consider using non retina images for some. Honestly most people wont notice. iOS will gracefully use the non retina on retina. This can save a ton of space,

考虑对某些人使用非视网膜图像。老实说,大多数人不会注意到。iOS 将优雅地使用视网膜上的非视网膜。这可以节省大量空间,

Also consider using jpeg files instead of PNG for some of the files if you do not need transparency. Jpeg files are less efficient but can be much smaller. Compare both. Depends on the extent to which the images are continuous tone.

如果您不需要透明度,还可以考虑对某些文件使用 jpeg 文件而不是 PNG。Jpeg 文件效率较低,但可以小得多。比较两者。取决于图像连续色调的程度。

By default PNG file are 32 bit. 24 bit color and 8 buit alpha/transparency. You can save a bit of size by going to 24 bit. You can also save a lot of size going to 16 bit color or below. At 8 bit PNG files use a color lookup table. Play with Photoshop and the save for we options at PNG with bit depth 8 and below.

默认情况下,PNG 文件为 32 位。24 位颜色和 8 位 alpha/透明度。您可以通过转到 24 位来节省一些大小。您还可以节省大量 16 位颜色或以下的尺寸。8 位 PNG 文件使用颜色查找表。在 PNG 中使用 Photoshop 和 Save for we 选项,位深度为 8 及以下。

I have all sorts of expensive compressing software but often use the $8

我有各种昂贵的压缩软件,但经常使用 8 美元

https://itunes.apple.com/us/app/lossless-photo-squeezer/id704083918?mt=12

https://itunes.apple.com/us/app/lossless-photo-squeezer/id704083918?mt=12

Try the 8 bit PNG option and the JPEG options.

尝试 8 位 PNG 选项和 JPEG 选项。

EDITI did some research. I had always know Fireworks did better PNG compression. I did not realize that there was an 8bit PNG with an 8 Bit alpha channel. Photoshop supports 8 bit with a 1 bit Alpha Channel. I have always told people to use 32 bit PNG if their transparency needed more than 1 bit. In the future I will let them know the 8 bit with 8 bit alpha may be the better route, They just can use Photoshop for the final save of the file. They just need to save a 32 bit and compress elsewhere.

编辑我做了一些研究。我一直都知道 Fireworks 的 PNG 压缩效果更好。我没有意识到有一个带有 8 位 alpha 通道的 8 位 PNG。Photoshop 支持 8 位和 1 位 Alpha 通道。如果透明度需要超过 1 位,我一直告诉人们使用 32 位 PNG。以后我会让他们知道 8 位加 8 位 alpha 可能是更好的路线,他们只能使用 Photoshop 来最终保存文件。他们只需要保存一个 32 位并压缩到其他地方。

http://calendar.perfplanet.com/2010/png-that-works/

http://calendar.perfplanet.com/2010/png-that-works/

David

大卫