Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to link "Sdk Assemblies Only"?

I'm developing an Android app using Xamarin and Visual Studio 2013. If you go to Project Properties / Android Options / Linking there are three options: None, Sdk Assemblies Only, and Sdk and User Assemblies.

My questions is: When would you select the option Sdk Assemblies Only option? Don't you always want to include user assemblies in a Release build?

Update The word Linkingis actually used to mean Unlinking in the Xamarin docs. It all makes sense when the text is preprocessed with that condition.

like image 772
Arne Evertsson Avatar asked Sep 24 '14 09:09

Arne Evertsson


2 Answers

You'd use the Sdk Assemblies Only option when you want unused Xamarin.Android assemblies you have linked to your project to be remove when the APK is built. A full list of these assemblies can be found here.

Say you have added the System.Net assembly to your project but haven't actually used it in your code and forgot to remove it. Specifying the linker option Sdk Assemblies Only will cause the build chain to strip the assembly from your final APK thus reducing the overall size of the application.

You can verify this behaviour by looking into the extracting the final APK as a zip file and inspecting the assemblies directory:

enter image description here

In the above image, you'll see that System.Net.dll and System.Xml.dll are in the Don't Link generated APK whereas they have been removed from the APK which was build with Sdk Assemblies Only. These were project references but are never used in the source code, Xamarin detects this through static analysis and then excludes them from the APK.

like image 180
matthewrdev Avatar answered Nov 09 '22 12:11

matthewrdev


Xamarin.Android applications use a linker in order to reduce the size of the application.The default value is SdkOnly

  • None: No linking will be attempted.
  • SdkOnly: Linking will be performed on the base class libraries only, not user's assemblies.
  • Full: Linking will be performed on base class libraries and user assemblies. For more details refer here.. Note: if you are facing an issue with linking such as

"GetAdditionalResourcesFromAssemblies" task failed unexpectedly. System.IO.FileNotFoundException: . Perhaps it doesn't exist in the Mono for Android profile?

then recheck your xamarin.Android project settings and set the below tag,

<AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>

Hope it will be helpful.

like image 41
Joy Rex Avatar answered Nov 09 '22 13:11

Joy Rex