iosxcodesvgsizeipa

iOS App Size much bigger than expected using SVGs


We are working on optimizing the size of our app, and there is something we can't figure out. It looks like Xcode includes rasterized versions of our SVG images, increasing the size of our app significantly.

Given these steps:

  1. Create a project from scratch in Xcode 15 (or 14.2)
  2. Add an SVG in the .xcassets with "Single Scale" and "Preserve Vector data" (like this one, notice it's 9KB)
  3. Select Team and then Archive
  4. Export AdHoc and select a device to do the App Thinning (I usually use iPhone 14)
  5. Change .ipa to .zip, decompress .zip and "Show Package Contents" in .app
  6. Notice Assets.car size, over 100KB
  7. Run xcrun --sdk iphoneos assetutil --info Assets.car and check the json, notice there is a vector image, but also images @1x and @3x, adding up over 90KB (because these are not vectors)

Why is Xcode adding rasterized images in the .car apart of the vectorial one? This is increasing our app size some MBs (we have many SVGs), which I think is unnecessary and goes against the idea of using vectors in my opinion.

Does someone have a clue why is this happening? Thanks!


Solution

  • A common misconception is that iOS 13 added native support for SVG images in asset catalogs. This is not correct.

    What was made available in Xcode 12 was the ability to add SVGs to asset catalogs and have the relevant raster image variants created at build time.

    iOS 13 (and the relevant versions of macOS, tvOS) released in 2020 have the ability to identify the correct raster image when an SVG is referred to. This is why there is a requirement to target iOS 13 as a minimum when using SVGs, not because of any native support for SVGs.

    As with adding PDFs to asset catalogs, adding SVGs is primarily a way of simplifying workflow and removing the potential of adding an incorrect resolution as a variant.

    There are 3rd party frameworks available with varying levels of SVG support that may meet your needs or you can go back to manually rasterising your images and adding the variants directly which will give you more control over image properties.

    Depending on the minimum iOS level and (therefore the oldest devices) you are targeting you may not require all variants of your images.