Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] remove %(TrimMode)=link metadata (#8624)
Browse files Browse the repository at this point in the history
To keep app sizes down in the .NET 6 timeframe, we special-cased
existing AndroidX and GPS packages so they were always trimmed.

Modern packages mark themselves trimmable with `$(IsTrimmable)` or the
assembly-level attribute.

For nearly 2 years, we've applied the appropriate trimming setting in
these packages:

* dotnet/android-libraries#520
* xamarin/GooglePlayServicesComponents#597

We should be able to remove this now in .NET 9.

With this change in place, an existing app size regression test failed that was
using an old version of Xamarin.Forms (and AndroidX):

    Saving apk description to 'BuildReleaseArm64XFormsDotNet.apkdesc'
    Size difference in bytes ([*1] apk1 only, [*2] apk2 only):
    253,683 assemblies/Xamarin.AndroidX.Core.dll
    179,063 assemblies/Xamarin.Google.Android.Material.dll
    157,233 assemblies/Xamarin.AndroidX.AppCompat.dll
    104,239 assemblies/Xamarin.AndroidX.Media.dll *2
     52,862 assemblies/Xamarin.AndroidX.Annotation.dll *2
     48,743 assemblies/Xamarin.AndroidX.RecyclerView.dll
     39,419 assemblies/Xamarin.AndroidX.Transition.dll *2
     38,993 assemblies/Xamarin.AndroidX.Browser.dll *2

To avoid this increase: update the app size test from Xamarin.Forms 4.7.0.1142
to 5.0.0.2515.

This allowed us to no longer need the `%(TrimMode)=link` changes, however
updating Xamarin.Forms increased app size in other ways.

* New AndroidX libraries contain considerable more `AndroidResource`
and Java code.

* New AndroidX `.dll` files appeared for new packages.

* Luckily, it appears that no AndroidX `.dll` files grew in size, which is what
would be the result of the `%(TrimMode)=link` change if it were still needed.

Overall app size change in this test:

    --"PackageSize": 7941134
    ++"PackageSize": 9593384
  • Loading branch information
jonathanpeppers authored Jan 11, 2024
1 parent de9d6c8 commit a34988c
Show file tree
Hide file tree
Showing 3 changed files with 758 additions and 397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ This file contains the .NET 5-specific targets to customize ILLink
Condition="'$(VSAndroidDesigner)' != ''"
Value="$(VSAndroidDesigner)"
Trim="true" />
<!-- TODO: remove setting the trim mode here, once the support packages are updated to NET6 and compatability packages not needed -->
<ResolvedFileToPublish
Condition=" '$(AndroidLinkMode)' == 'SdkOnly' and ( $([System.String]::Copy(%(Filename)).StartsWith ('Xamarin.AndroidX.')) or $([System.String]::Copy(%(Filename)).StartsWith ('Xamarin.Google.')) or $([System.String]::Copy(%(Filename)).StartsWith ('Xamarin.GooglePlayServices.')) ) ">
<TrimMode>link</TrimMode>
</ResolvedFileToPublish>

<!--
Used for the <ILLink CustomData="@(_TrimmerCustomData)" /> value:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void BuildReleaseArm64 ([Values (false, true)] bool forms)

if (forms) {
proj.PackageReferences.Clear ();
proj.PackageReferences.Add (KnownPackages.XamarinForms_4_7_0_1142);
proj.PackageReferences.Add (KnownPackages.XamarinForms_5_0_0_2515);
}

byte [] apkDescData;
Expand Down
Loading

0 comments on commit a34988c

Please sign in to comment.