Understand this is nothing to do with the size of ServiceStack Client dlls. You can read about Xamarin Application Sizes in their Docs which will show you the different sizes for the Xamarin software that make up your packaged Application.
If you check the output folder of the iOS project you’ll see the actual bytes sizes for each of the ServiceStack Client dlls, i.e:
- 271kb for ServiceStack.Text
- 136kb for ServiceStack.Client
and the platform-specific dll that contains IosPclExportClient
is only:
- 28kb for ServiceStack.Pcl.iOS.dll
I hope this makes it clear the 26kb footprint or actual sizes of ServiceStack Client .dlls is insignificant, it’s the mono dependencies that Xamarin links together that makes up the bulk of the App size. Not configuring the 28kb IosPclExportClient
iOS platform specific implementation is not an option, it’s what binds iOS implementation to the Exported PCL API’s.
The HelloMobile iOS project was using the old ServiceStack.Client.Pcl packages which were deprecated at the end of last year before Apple forced Xamarin to move everyone to their new Unified API.
To see if it made a difference I’ve since removed System.Xml
support as well as Microsoft.CSharp
dependencies in ServiceStack PCL Client removes support for XmlServiceClient
and dynamic
from the latest v4.0.43 packages on MyGet which are both heavy technologies that shouldn’t really be used in mobile apps.
But I don’t think it helps as after creating a new iOS Phone project with the client packages I can see the size jumps from the default empty iPhone app template size of 8MB:
to 9.64MB after adding the v4.0.43 ServiceStack.Client NuGet packages:
Configuring the 28kb IosPclExportClient
makes it jump to 41.36MB:
But as mentioned earlier the Client library is useless without it, I expect all this is doing is forcing Xamarin to bundle the ServiceStack Client libraries dependencies where previously it didn’t.
This is what it looks like after enabling some optimizations, after changing the iOS Build Linker behavior to link all the assemblies the size drops to 31.9MB:
Note: this isn’t recommended for reflection-heavy libraries like serializers
Then if you only wanted to support iPhone 5s+ you can enable just the ARM64 CPU Architecture which since you’re only supporting 1 CPU effectively halves the amount of space to 16.47MB:
Using ARM Thumb support at the cost of a little CPU makes the binary a little smaller at 15.45MB:
Which is the smallest it goes down to with the primary UI optimizations. But not recommended since you could run into serialization issues with Link All Assemblies. Without that optimization compiling for just ARM64 the size is 20MB.
If we look at the build output you can see all the different assemblies being included:
/lib/mono/Xamarin.iOS/System.dll
/lib/mono/Xamarin.iOS/Xamarin.iOS.dll
../packages/Xamarin.TestCloud.Agent.0.14.1/lib/Xamarin.iOS10/Calabash.dll
../packages/ServiceStack.Interfaces.4.0.43/lib/portable-*/ServiceStack.Interfaces.dll
../packages/ServiceStack.Text.4.0.43/lib/portable-*/ServiceStack.Text.dll
../packages/ServiceStack.Client.4.0.43/lib/Xamarin.iOS10/ServiceStack.Client.dll
../packages/ServiceStack.Client.4.0.43/lib/Xamarin.iOS10/ServiceStack.Pcl.iOS.dll
/lib/mono/Xamarin.iOS/System.Core.dll
/lib/mono/Xamarin.iOS/mscorlib.dll
/lib/mono/Xamarin.iOS/Facades/System.Collections.Concurrent.dll
/lib/mono/Xamarin.iOS/Facades/System.Collections.dll
/lib/mono/Xamarin.iOS/Facades/System.ComponentModel.Annotations.dll
/lib/mono/Xamarin.iOS/Facades/System.ComponentModel.EventBasedAsync.dll
/lib/mono/Xamarin.iOS/Facades/System.ComponentModel.dll
/lib/mono/Xamarin.iOS/Facades/System.Diagnostics.Contracts.dll
/lib/mono/Xamarin.iOS/Facades/System.Diagnostics.Debug.dll
/lib/mono/Xamarin.iOS/Facades/System.Diagnostics.Tools.dll
/lib/mono/Xamarin.iOS/Facades/System.Dynamic.Runtime.dll
/lib/mono/Xamarin.iOS/Facades/System.Globalization.dll
/lib/mono/Xamarin.iOS/Facades/System.IO.dll
/lib/mono/Xamarin.iOS/Facades/System.Linq.Expressions.dll
/lib/mono/Xamarin.iOS/Facades/System.Linq.Parallel.dll
/lib/mono/Xamarin.iOS/Facades/System.Linq.Queryable.dll
/lib/mono/Xamarin.iOS/Facades/System.Linq.dll
/lib/mono/Xamarin.iOS/Facades/System.Net.NetworkInformation.dll
/lib/mono/Xamarin.iOS/Facades/System.Net.Primitives.dll
/lib/mono/Xamarin.iOS/Facades/System.Net.Requests.dll
/lib/mono/Xamarin.iOS/Facades/System.ObjectModel.dll
/lib/mono/Xamarin.iOS/Facades/System.Reflection.Extensions.dll
/lib/mono/Xamarin.iOS/Facades/System.Reflection.Primitives.dll
/lib/mono/Xamarin.iOS/Facades/System.Reflection.dll
/lib/mono/Xamarin.iOS/Facades/System.Resources.ResourceManager.dll
/lib/mono/Xamarin.iOS/Facades/System.Runtime.Extensions.dll
/lib/mono/Xamarin.iOS/Facades/System.Runtime.InteropServices.WindowsRuntime.dll
/lib/mono/Xamarin.iOS/Facades/System.Runtime.InteropServices.dll
/lib/mono/Xamarin.iOS/Facades/System.Runtime.Numerics.dll
/lib/mono/Xamarin.iOS/Facades/System.Runtime.Serialization.Json.dll
/lib/mono/Xamarin.iOS/Facades/System.Runtime.Serialization.Primitives.dll
/lib/mono/Xamarin.iOS/Facades/System.Runtime.Serialization.Xml.dll
/lib/mono/Xamarin.iOS/Facades/System.Runtime.dll
/lib/mono/Xamarin.iOS/Facades/System.Security.Principal.dll
/lib/mono/Xamarin.iOS/Facades/System.ServiceModel.Http.dll
/lib/mono/Xamarin.iOS/Facades/System.ServiceModel.Primitives.dll
/lib/mono/Xamarin.iOS/Facades/System.Text.Encoding.Extensions.dll
/lib/mono/Xamarin.iOS/Facades/System.Text.Encoding.dll
/lib/mono/Xamarin.iOS/Facades/System.Text.RegularExpressions.dll
/lib/mono/Xamarin.iOS/Facades/System.Threading.Tasks.Parallel.dll
/lib/mono/Xamarin.iOS/Facades/System.Threading.Tasks.dll
/lib/mono/Xamarin.iOS/Facades/System.Threading.dll
/lib/mono/Xamarin.iOS/Facades/System.Xml.ReaderWriter.dll
/lib/mono/Xamarin.iOS/Facades/System.Xml.XDocument.dll
/lib/mono/Xamarin.iOS/Facades/System.Xml.XmlSerializer.dll
../packages/Xamarin.TestCloud.Agent.0.14.1/lib/Xamarin.iOS10/Calabash.dll
../packages/ServiceStack.Interfaces.4.0.43/lib/portable-*/ServiceStack.Interfaces.dll
../packages/ServiceStack.Text.4.0.43/lib/portable-*/ServiceStack.Text.dll
../packages/ServiceStack.Client.4.0.43/lib/Xamarin.iOS10/ServiceStack.Client.dll
../packages/ServiceStack.Client.4.0.43/lib/Xamarin.iOS10/ServiceStack.Pcl.iOS.dll
Note: directories are truncated to prevent wrapping.
A number of those .dll’s shouldn’t be needed but are still included. e.g. There’s nothing that references System.Xml in the PCL builds explicitly but the output dlls still contains a reference to System.Xml. I’ve spent the day trying to track down what’s causing the reference to System.Xml but wasn’t able to find anything. So for the time being if you want smaller binaries than above you’ll need to adopt a 3rd party HTTP library.