Skip to content
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

Mark all assemblies as Trimmable via Directory.Build.props. #520

Merged
merged 1 commit into from
Mar 31, 2022

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Mar 31, 2022

Fixes: #519

In Xamarin.Android Classic we link all assemblies by default unless the user opts out. In .NET6+, assemblies must opt-in to being linked by setting $(IsTrimmable).

We already had this for packages using the default AndroidX template, but AndroidX dependencies (like Kotlin) bound in this repository use other templates that did not include trimming.

Enable trimming via Directory.Build.targets to ensure it affects all assemblies.

From CI build for Xamarin.Kotlin.Stdlib.dll:
image

@jpobst jpobst marked this pull request as ready for review March 31, 2022 17:13
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to get the assembly right:

image

Do we also need to bump some version numbers & dependencies to fully fix #519?

@jpobst jpobst merged commit c18c976 into main Mar 31, 2022
@jpobst jpobst deleted the trim-all-the-things branch March 31, 2022 18:03
@jpobst
Copy link
Contributor Author

jpobst commented Mar 31, 2022

Yes, we will need to bump and release all of AndroidX in a separate PR.

@@ -15,6 +15,9 @@

<!-- .NET 6+ packages support back to API-21 -->
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>

<!-- Mark .NET6+ packages as supporting trimming -->
<IsTrimmable>true</IsTrimmable>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this pull request Jan 10, 2024
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.
jonathanpeppers added a commit to dotnet/android that referenced this pull request Jan 11, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.NET MAUI size regression
4 participants