Skip to content
Use the new Xamarin.Android features and open up an issue with your results
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE Update issue templates Aug 20, 2019
Images Add two images Aug 20, 2019
.gitignore
LICENSE
README.md

README.md

Android Performance and App Size Challenge

Use the new Xamarin.Android features and open up an issue with your results

Before you start

  1. Ensure you're on at least a 16.2/8.2 version of Visual Studio 2019 or Visual Studio for Mac respectfully.

  2. Enable Diagnostic MSBuild Output or use MSBuild BinLog.

  1. Open up the Android Device Log by going to Tools > Android > Device Log

  2. Familiarize yourself with the Android Project Options Screen

You're ready to begin the challenge! Pick your challenge below, or do all three!

Build Times

Within a .csproj, add the following properties to your current configuration:

<PropertyGroup>
    <AndroidUseAapt2>true</AndroidUseAapt2>
    <AndroidDexTool>d8</AndroidDexTool>
    <DebugType>portable</DebugType>
    <ProduceReferenceAssembly>True</ProduceReferenceAssembly>
</PropertyGroup>

Build Times should be measured with a Debug configuration. To measure the performance, enable Diagnostic MSBuild Output or use MSBuild BinLog to provide the time elapsed.

Bonus: If you can include a full MSBuild Output or MSBuild BinLog, this will help us understand where time is allocated to each target and task while building your app! This will help us understand bottlenecks and where to improve in the future.

Before Cold Build Times Changes:

Time Elapsed 00:00:15.77

After Cold Build Times Changes:

Time Elapsed 00:00:14.85

Note: To do a cold build, Clean your project prior to building.

Before Incremental Build Times Changes:

Time Elapsed 00:00:02.67

After Incremental Build Times Changes:

Time Elapsed 00:00:02.43

Note: To do an incremental build, change a single piece of code (XAML / C# / etc) and deploy your project.

Startup Times

Within a .csproj, add the following property to your release configuration:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> 
    <AndroidEnableProfiledAot>true</AndroidEnableProfiledAot> 
</PropertyGroup>

Startup Times should be measured with a Release configuration. To measure the performance, with the Android Device Log, add a filter to search for ActivityManager: Displayed to which you will be provided a timing of your application such as:

Before Startup Tracing:

2019-08-19 09:35:43.374 1870-1892/? I/ActivityManager: Displayed com.companyname.startuptiming/md5984e4549386b302a2fd47914e0849f36.MainActivity: +2s995ms

After Startup Tracing:

2019-08-19 09:37:40.504 1870-1892/? I/ActivityManager: Displayed com.companyname.startuptiming/md5984e4549386b302a2fd47914e0849f36.MainActivity: +1s760ms

Note: The checkbox for Startup Tracing is included in Visual Studio 2019 16.3 Preview 2 and Visual Studio 2019 8.3 Preview 2.

Application Size

Within a .csproj, add the following properties to your release configuration:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> 
    <AndroidPackageFormat>aab</AndroidPackageFormat>
    <AndroidDexTool>d8</AndroidDexTool>
    <AndroidLinkTool>r8</AndroidLinkTool>
</PropertyGroup>

Now create an Android App Bundle via the command line:

msbuild -restore AndroidApp.csproj
  -t:SignAndroidPackage
  -p:Configuration=Release
  -p:AndroidKeyStore=True
  -p:AndroidSigningKeyStore=com.contoso.keystore
  -p:AndroidSigningStorePass=password
  -p:AndroidSigningKeyAlias=keyAlias
  -p:AndroidSigningKeyPass=password

Application size should be measured with a Release configuration and signed package. To measure the perceived app download size, you can use Android Studio's APK Analyzer or with the following command in your Android SDK/tools/bin location:

apkanalyzer -h apk download-size myapk.apk

or

apkanalyzer -h apk download-size myaab.aab

Note: apkanalyzer may not work on Windows.

Before Application Size Changes:

App download size: 23.6MB

After Application Size Changes:

App download size: 4.82MB
You can’t perform that action at this time.