Adding EmbeddedResources in PCL triples additional size in iOS archive

CameronFulfordCameronFulford CAMember

I have a cross-platform PCL in which I want to put some embedded resources that are approximately 20MB in size. I have them marked as EmbeddedResource under the Build action. I noticed that the resulting iOS archive built in Release grows by approximately 60MB however, triple the size of the resources themselves. In Android, including these resources adds about 20MB to the apk, as I expected. As a test, I also tried setting the build action to None and setting Copy to Output Directory, then I removed the resources from my project altogether. Here's what happened to the size of my archives:

iOS
EmbeddedResource: 122MB
None and Copy: 82.5MB
Removed: 61.7MB

Android
EmbeddedResource: 53MB
None and Copy: 33.2MB
Removed: 33.2MB

My questions are:
1) What is happening in iOS when I add my files as EmbeddedResources and why do they take up 3x space than what I expected?
2) Is Copy to Output Directory not including the files in my Android apk? It doesn't seem to add any files compared to removing them from the project.
3) It seemed like a good idea to put shared resources in my PCL, but if this is not actually a good idea due to these effects, what is the best approach?

Thanks,

Cameron

Best Answer

Answers

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Each assembly is included in the binary once for each architecture. I'm not sure if that is a necessary behavior or just a matter of convenience or oversight. Regardless, the best way to include images in your app is as regular resources, not embedded resources.

  • @adamkemp, thanks for your input. Actually, my resources are not images (they are zip files). I'm still not sure I understand what you are getting at. Is there a reason why in Android adding the embedded resources only adds 1x space, but in iOS it ends up adding 3x space? Also, I am trying to centralize it in my PCL to put everything cross-platform in one project (rather than across several), which has obvious benefits. So what other option do I have other than EmbeddedResource in the PCL?

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Only in iOS 9 (when linking against the iOS 9 SDK) will users download just one slice. For now users download all slices. It's unfortunate, but that's just how it works. Each architecture contains its own copy of the assemblies.

    On Android the assemblies are not precompiled ("AOT", ahead of time) at build time. Therefore Android apps only contain one copy of the assembly, and it is JIT compiled.

Sign In or Register to comment.