Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Conversation

@jonathanpeppers
Copy link
Member

Description of Change

Context: dotnet/android#2982

The Blank Xamarin.Forms app template in VS 2019 takes longer to build
than in VS 2017. A little research is showing that this is due to use
of the 28.x support libraries... For example, the build includes ~20
more jar files in the template from 2019 than 2017. The
_CompileDex step alone goes from ~15.2s to ~18.2s.

This lead me down the road of investigating if we can remove any
support libraries by default in Xamarin.Forms apps. I am also seeing
if there is more we can do in Xamarin.Android for this problem, in
general.

It looks like we can remove:

  • Xamarin.Android.Support.v7.MediaRouter
  • Xamarin.Android.Support.Media.Compat

Neither of these appear to be used, but have been listed as
dependencies of Xamarin.Forms for a long time.

Results

I made these changes, then did a Debug build of
Xamarin.Forms.ControlGallery.Android.csproj for comparison.

Comparing dex file sizes (in bytes):

Before:
3428092 classes.dex
3265616 classes2.dex
6693708 total
After:
4938000 classes.dex
1098772 classes2.dex
6036772 total

This looks like it could potentially save ~600KB of compiled dex code
on every Xamarin.Forms app.

Comparing methods:

Before:
classes.dex  11,492 methods
classes2.dex 19,451 methods
total        30,943 methods
After:
classes.dex  22,171 methods
classes2.dex  7,635 methods
total        29,806 methods

~1,137 methods removed, which should help with the dex limit.

Comparing APK sizes (in bytes):

Before:
26442597 AndroidControlGallery.AndroidControlGallery-Signed.apk
After:
25741701 AndroidControlGallery.AndroidControlGallery-Signed.apk

~700KB smaller APK, due to less .NET assemblies & dex code.

Comparing build time (this was using dx):

Before:
19785 ms  CompileToDalvik                            1 calls
After:
18532 ms  CompileToDalvik                            1 calls

Looks like it saved over a second of build time for this project.

Seems like an "easy win", let's do this!

Issues Resolved

none

API Changes

None

Platforms Affected

  • Android

Behavioral/Visual Changes

Only known behavior, is a user might have to add <PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="28.0.0.1" /> if they are using it directly.

Before/After Screenshots

Not applicable

Testing Procedure

If Xamarin.Forms apps build with this change, things should work.

PR Checklist

  • Has automated tests
  • Rebased on top of the target branch at time of PR
  • Changes adhere to coding standard

Context: dotnet/android#2982

The Blank Xamarin.Forms app template in VS 2019 takes longer to build
than in VS 2017. A little research is showing that this is due to use
of the 28.x support libraries... For example, the build includes ~20
*more* jar files in the template from 2019 than 2017. The
`_CompileDex` step alone goes from ~15.2s to ~18.2s.

This lead me down the road of investigating if we can remove any
support libraries by default in Xamarin.Forms apps. I am also seeing
if there is more we can do in Xamarin.Android for this problem, in
general.

It looks like we can remove:

* Xamarin.Android.Support.v7.MediaRouter
* Xamarin.Android.Support.Media.Compat

Neither of these appear to be used, but have been listed as
dependencies of Xamarin.Forms for a long time.

~~ Results ~~

I made these changes, then did a `Debug` build of
`Xamarin.Forms.ControlGallery.Android.csproj` for comparison.

Comparing dex file sizes (in bytes):

    Before:
    3428092 classes.dex
    3265616 classes2.dex
    6693708 total
    After:
    4938000 classes.dex
    1098772 classes2.dex
    6036772 total

This looks like it could potentially save ~600KB of compiled dex code
on every Xamarin.Forms app.

Comparing methods:

    Before:
    classes.dex  11,492 methods
    classes2.dex 19,451 methods
    total        30,943 methods
    After:
    classes.dex  22,171 methods
    classes2.dex  7,635 methods
    total        29,806 methods

~1,137 methods removed, which should help with the dex limit.

Comparing APK sizes (in bytes):

    Before:
    26442597 AndroidControlGallery.AndroidControlGallery-Signed.apk
    After:
    25741701 AndroidControlGallery.AndroidControlGallery-Signed.apk

~700KB smaller APK, due to less .NET assemblies & dex code.

Comparing build time (this was using dx):

    Before:
    19785 ms  CompileToDalvik                            1 calls
    After:
    18532 ms  CompileToDalvik                            1 calls

Looks like it saved over a second of build time for this project.

Seems like an "easy win", let's do this!
@rmarinho
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jonathanpeppers
Copy link
Member Author

I'm not sure how to read these CI results?

I mostly see things like this:

Access denied. public Build Service (xamarin) needs Edit build quality permissions for vstfs:///Build/Build/1115 in team project public to perform the action.

If there is a failure here, ping me and I'll take a look. Thanks!

Copy link
Contributor

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

UI Tests seem fine

Once @paymicro approves we can merge

@PureWeen PureWeen merged commit 78d662e into xamarin:master Apr 23, 2019
@jonathanpeppers jonathanpeppers deleted the android-remove-mediarouter branch April 25, 2019 12:52
@samhouts samhouts added this to the 4.1.0 milestone Jun 4, 2019
AxelUser pushed a commit to AxelUser/Xamarin.Forms that referenced this pull request Jun 15, 2019
Context: dotnet/android#2982

The Blank Xamarin.Forms app template in VS 2019 takes longer to build
than in VS 2017. A little research is showing that this is due to use
of the 28.x support libraries... For example, the build includes ~20
*more* jar files in the template from 2019 than 2017. The
`_CompileDex` step alone goes from ~15.2s to ~18.2s.

This lead me down the road of investigating if we can remove any
support libraries by default in Xamarin.Forms apps. I am also seeing
if there is more we can do in Xamarin.Android for this problem, in
general.

It looks like we can remove:

* Xamarin.Android.Support.v7.MediaRouter
* Xamarin.Android.Support.Media.Compat

Neither of these appear to be used, but have been listed as
dependencies of Xamarin.Forms for a long time.

~~ Results ~~

I made these changes, then did a `Debug` build of
`Xamarin.Forms.ControlGallery.Android.csproj` for comparison.

Comparing dex file sizes (in bytes):

    Before:
    3428092 classes.dex
    3265616 classes2.dex
    6693708 total
    After:
    4938000 classes.dex
    1098772 classes2.dex
    6036772 total

This looks like it could potentially save ~600KB of compiled dex code
on every Xamarin.Forms app.

Comparing methods:

    Before:
    classes.dex  11,492 methods
    classes2.dex 19,451 methods
    total        30,943 methods
    After:
    classes.dex  22,171 methods
    classes2.dex  7,635 methods
    total        29,806 methods

~1,137 methods removed, which should help with the dex limit.

Comparing APK sizes (in bytes):

    Before:
    26442597 AndroidControlGallery.AndroidControlGallery-Signed.apk
    After:
    25741701 AndroidControlGallery.AndroidControlGallery-Signed.apk

~700KB smaller APK, due to less .NET assemblies & dex code.

Comparing build time (this was using dx):

    Before:
    19785 ms  CompileToDalvik                            1 calls
    After:
    18532 ms  CompileToDalvik                            1 calls

Looks like it saved over a second of build time for this project.

Seems like an "easy win", let's do this!
@samhouts samhouts added the approved Has two approvals, no pending reviews, and no changes requested label Jul 2, 2019
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this pull request Dec 6, 2019
I also improved things so it's easier to bump this going forward:

* I added `KnownPackages.XamarinForms_LatestStable`, so tests won't
  need to change going forward.
* `Xamarin.Forms.Performance.Integration` now uses
  `<PackageReference/>`. The netstandard library was already.

I also removed some missing `Icon` files from the forms project. These
did not even exist.

`XamarinFormsPCL_2_3_4_231` was also unused, so I removed it.

I updated APK sizes, which I think is smaller because of:

xamarin/Xamarin.Forms#5941
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this pull request Dec 9, 2019
I also improved things so it's easier to bump this going forward:

* I added `KnownPackages.XamarinForms_LatestStable`, so tests won't
  need to change going forward.
* `Xamarin.Forms.Performance.Integration` now uses
  `<PackageReference/>`. The netstandard library was already.

I also removed some missing `Icon` files from the forms project. These
did not even exist.

`XamarinFormsPCL_2_3_4_231` was also unused, so I removed it.

I updated APK sizes, which I think is smaller because of:

xamarin/Xamarin.Forms#5941
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

approved Has two approvals, no pending reviews, and no changes requested p/Android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants