简体   繁体   中英

Xcode Asset Catalog: Only one copy of each image

So I created an Asset Catalog with four positions: two for iPhone and two for iPad. Now I drag'n'drop my images to the corresponding positions.

My Problem: Let's say I use the same image for iPhone @2x and iPad @1x. But Xcode creates a copy of the image, although the exact same image already exists.

So I tried solving this problem manually thanks to this answer . I open the .imageset folder and edit the "filename" in the Contents.json file like this: (I also delete the duplicate image in the folder.)

{
  "images" : [
    {
      "idiom" : "iphone",
      "scale" : "1x"
      "filename" : "myImage@1x.png"
    },
    {
      "idiom" : "iphone",
      "scale" : "2x",
      "filename" : "myImage@2x.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "1x",
      "filename" : "myImage@2x.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "2x",
      "filename" : "myImage@4x.png"
    }
  ],
  "info" : {
    "version" : 1,
    "author" : "xcode"
  }
}

After the build I take a look inside the .app file and at the Assets.car file, which contains the Xcode Asset Catalog.

The file size of the Assets.car file seems to be larger than I expected. As if the duplicate image I deleted was re-added in the build process.

To see if this is true, I changed every "filename" in the Contents.json to my @4x image:

{
  "images" : [
    {
      "idiom" : "iphone",
      "scale" : "1x"
      "filename" : "myImage@4x.png"
    },
    {
      "idiom" : "iphone",
      "scale" : "2x",
      "filename" : "myImage@4x.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "1x",
      "filename" : "myImage@4x.png"
    },
    {
      "idiom" : "ipad",
      "scale" : "2x",
      "filename" : "myImage@4x.png"
    }
  ],
  "info" : {
    "version" : 1,
    "author" : "xcode"
  }
}

After the build, I checked the file size fo the Assets.car. And it was significantly larger than before. Approximately four times the size of "myImage@4x.png" – although in my .imageset folder, there was only one "myImage@4x.png". So I assume Xcode added three copies of that image during the build process.

Does anyone know how to stop Xcode from adding these unnecessary copies? If your app contains many Asset Catalogs, the app size could increase significantly...

Thanks in advance for your help!

Slicing is the process of creating and delivering variants of the app bundle for different target devices.

from https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/AppThinning/AppThinning.html

App slicing prevents the app size to increase, because only the device specific resources are downloaded to the customers device.

Regarding the upload size from a developer perspective your worries seem to be true.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM