New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup [assembly: LinkerSafe] for binding projects #77

Closed
wants to merge 1 commit into
base: 27.x
from

Conversation

Projects
None yet
3 participants
@jonathanpeppers

jonathanpeppers commented Nov 16, 2017

Support Libraries Version (eg: 23.3.0):

26.1.0.1

Does this change any of the generated binding API's?

Nope

Describe your contribution

I discovered there was some file size that could be spared from the
support library assemblies in release APKs by using the Link all assemblies option. Since most Xamarin users will have the Link SDK only option set, we can save most Xamarin developers some APK size by
setting up the [assembly: LinkerSafe] attribute in the support
libraries.

To get an idea on what this saves, I tested the default Xamarin.Forms
template in VS for Mac. I then upgraded to TargetFrameworkVersion
8.0, API 26, Xamarin.Forms 2.5.0, and 26.1.0.1 support libraries.

Before:

  • Support libs: 5231104
  • APK: 20948533

After [assembly: LinkerSafe]:

  • Support libs: 2357248
  • APK: 17312534

It appears this change saves ~3.6MB in APK file size in release mode
for the default Xamarin.Forms template. The app still seemed to work fine,
it appears we can just get this file size for free!

Further details

Here is the results of zipinfo on the before APK:

-rw----     1.0 fat    17920 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Arch.Core.Common.dll
-rw----     1.0 fat    19456 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Arch.Lifecycle.Common.dll
-rw----     1.0 fat    13824 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Arch.Lifecycle.Runtime.dll
-rw----     1.0 fat    33280 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.Animated.Vector.Drawable.dll
-rw----     1.0 fat   110080 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.Annotations.dll
-rw----     1.0 fat  1408512 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.Compat.dll
-rw----     1.0 fat   349696 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.Core.UI.dll
-rw----     1.0 fat   134144 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.Core.Utils.dll
-rw----     1.0 fat   403968 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.Design.dll
-rw----     1.0 fat   237568 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.Fragment.dll
-rw----     1.0 fat   432128 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.Media.Compat.dll
-rw----     1.0 fat   131072 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.Transition.dll
-rw----     1.0 fat    30208 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.v4.dll
-rw----     1.0 fat  1071616 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.v7.AppCompat.dll
-rw----     1.0 fat    30720 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.v7.CardView.dll
-rw----     1.0 fat   194048 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.v7.MediaRouter.dll
-rw----     1.0 fat    35840 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.v7.Palette.dll
-rw----     1.0 fat   554496 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.v7.RecyclerView.dll
-rw----     1.0 fat    22528 b- stor 17-Nov-15 08:44 assemblies/Xamarin.Android.Support.Vector.Drawable.dll

Here is the results of the after APK with [assembly: LinkerSafe]:

-rw----     1.0 fat     5120 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Arch.Core.Common.dll
-rw----     1.0 fat    13824 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Arch.Lifecycle.Common.dll
-rw----     1.0 fat     5120 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Arch.Lifecycle.Runtime.dll
-rw----     1.0 fat     5632 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.Animated.Vector.Drawable.dll
-rw----     1.0 fat     5632 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.Annotations.dll
-rw----     1.0 fat   290816 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.Compat.dll
-rw----     1.0 fat   122368 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.Core.UI.dll
-rw----     1.0 fat    35840 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.Core.Utils.dll
-rw----     1.0 fat   403968 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.Design.dll
-rw----     1.0 fat   177664 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.Fragment.dll
-rw----     1.0 fat   157696 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.Media.Compat.dll
-rw----     1.0 fat   131072 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.Transition.dll
-rw----     1.0 fat     9728 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.v4.dll
-rw----     1.0 fat   409088 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.v7.AppCompat.dll
-rw----     1.0 fat    30720 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.v7.CardView.dll
-rw----     1.0 fat   194048 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.v7.MediaRouter.dll
-rw----     1.0 fat    35840 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.v7.Palette.dll
-rw----     1.0 fat   317952 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.v7.RecyclerView.dll
-rw----     1.0 fat     5120 b- stor 17-Nov-16 07:31 assemblies/Xamarin.Android.Support.Vector.Drawable.dll

Here is my packages.config:

<packages>
  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="monoandroid71" />
  <package id="Xam.Plugin.Connectivity" version="3.0.3" targetFramework="monoandroid71" />
  <package id="Xamarin.Android.Arch.Core.Common" version="1.0.0" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Arch.Lifecycle.Common" version="1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Arch.Lifecycle.Runtime" version="1.0.0" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.Annotations" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.Compat" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.Core.UI" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.Core.Utils" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.Design" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.Fragment" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.Media.Compat" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.Transition" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.v4" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.v7.AppCompat" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.v7.CardView" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.v7.MediaRouter" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.v7.Palette" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.v7.RecyclerView" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Android.Support.Vector.Drawable" version="26.1.0.1" targetFramework="monoandroid80" />
  <package id="Xamarin.Forms" version="2.5.0.77107" targetFramework="monoandroid71" />
</packages>
Setup [assembly: LinkerSafe] for binding projects
I discovered there was some file size that could be spared from the
support library assemblies in release APKs by using the `Link all
assemblies` option. Since most Xamarin users will have the `Link SDK
only` option set, we can save most Xamarin developers some APK size by
setting up the `[assembly: LinkerSafe]` attribute in the support
libraries.

To get an idea on what this saves, I tested the default Xamarin.Forms
template in VS for Mac. I then upgraded to `TargetFrameworkVersion`
8.0, API 26, Xamarin.Forms 2.5.0, and 26.1.0.1 support libraries.

Before:
- Support libs: 5231104
- APK: 20948533

After `[assembly: LinkerSafe]`:
- 2357248
- 17312534

It appears this change saves ~3.6MB in APK file size in release mode
for the default Xamarin.Forms template.

@jonathanpeppers jonathanpeppers requested a review from Redth Nov 16, 2017

@dnfclas

This comment has been minimized.

dnfclas commented Nov 16, 2017

@jonathanpeppers,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by .NET Foundation. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot

@Redth

Can you PR against 27.x branch instead? We're going to try including this in the QA cycle for the 27 release first. :)

@jonathanpeppers jonathanpeppers changed the base branch from 26.1.x to 27.x Nov 30, 2017

@jonathanpeppers

This comment has been minimized.

jonathanpeppers commented Nov 30, 2017

Yeah, no problem.

Looks like I'll have to rework this a bit, though. Conflicts!

@Redth

This comment has been minimized.

Member

Redth commented Nov 30, 2017

Ahh i can just work it in manually then, just thought if it merged nicely I'd ask you to do it.

Redth added a commit that referenced this pull request Nov 30, 2017

Added LinkerSafe to all assemblies
See the original PR #77 by @jonathanpeppers

Basically we can enable these assemblies to be linked when projects are set to Link SDK Assemblies only.

This can always be opted out of by specifying `AndroidLinkSkip` in your .csproj’s:
```
<PropertyGroup>
  <AndroidLinkSkip>Xamarin.Android.Support.Compat;Xamarin.Android.Support.Compat.UI;...</AndroidLinkSkip>
</PropertyGroup>
```
@Redth

This comment has been minimized.

Member

Redth commented Dec 11, 2017

Manually adding this...

@Redth Redth closed this Dec 11, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment