title: Slow app build - Xamarin for Visual Studio
body: <p>The build/deploy of my Xamarin.Android app is painfully slow these days. I cannot remember it being this slow before.</p>
  
  <p>I have enabled:</p>
  
  <ul>
  <li>Use shared runtime</li>
  <li>Fast deployment</li>
  </ul>
  
  <p>Enabling or disabling these settings doesn't make any difference. In both scenarios it takes about 2 minutes and 20 seconds (up to over 3 minutes!) to build/deploy my app.
  Using a real device or the Visual Studio emulator for Android doesn’t make a difference as well.</p>
  
  <p>Why could this be so extremely slow? Am I not using the right settings?</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>Yesterday (november 14th) I updated Xamarin.VS to 4.2.1.58. No improvements in build duration.</p>
  
  <p>We are using TeamCity to build release versions of our app, the TeamCity statistics show perfectly what I'm talking about.</p>
  
  <p>In the graph below, I selected last quarter as the date range. See the major increase in build duration. Now, I don't mind waiting 3 minutes for a release build, but it's not acceptable when debugging.</p>
  
  <p><a href="https://i.stack.imgur.com/288aS.png"><img src="https://i.stack.imgur.com/288aS.png" alt="Nov. 7, before installing latest Xamarin update"></a>
  <a href="https://i.stack.imgur.com/YV6EG.png"><img src="https://i.stack.imgur.com/YV6EG.png" alt="Nov. 8, after installing update and targetting Android 7"></a></p>
  
  <p><strong>UPDATE 3</strong></p>
  
  <p>Jon, thanks for your help.</p>
  
  <p>In the meantime, I have done some research myself in the build logs and found the duration per build task as well. I found that somehow <code>GetAdditionalResourcesFromAssemblies</code> takes a lot of time.</p>
  
  <p>The amount of resources I have in the app didn't change dramatically, so this got me thinking: could it be another assembly that I'm using..</p>
  
  <p>I then did a checkout of revision 1029 (which was the last revision that took about a minute to build) and tried to debug it in the updated environment. It still built within 1m30s...</p>
  
  <p>So:</p>
  
  <ul>
  <li>It's probably not the VS Xamarin update (else revision 1029 would build slow as well)</li>
  <li>It's probably not fast deployment, the duration increased in the build process</li>
  </ul>
  
  <p>So what was changed between revision 1029 and 1030 of my app?</p>
  
  <ol>
  <li>Updated Xamarin for Visual Studio to 4.2.0.719</li>
  <li>Installed Android 7.0 SDK platform in Android SDK Manager</li>
  <li>Changed <code>Compile using Android version</code> to Android 7.0 in project properties</li>
  <li>Updated Xamarin.Android Support Libraries from 23.4.0.1 to 24.2.1</li>
  </ol>
  
  <p><strong>Change 4</strong> was why I updated in the first place, I wanted to use <code>Bottomsheet</code>, which was improved in version 24. But the support library nugets were targeting Android 7.0, so I had to do 1-3 in order to be able to update the support libraries.</p>
  
  <p>Could something have changed in the Support Library bindings that caused all this? I checked the internet for other devs having this issue, and found <a href="https://forums.xamarin.com/discussion/12172/slow-build-and-deployment-time-when-referencing-android-support-v7-appcompat-and-googleplayservice">this</a> in the Xamarin forum. Setting <code>AndroidExplicitCrunch</code> build property to <code>true</code> seems to fix it there, but when I tried that, I got another build error.</p>
  
  <p>Anyway, that's what I've tried in the meantime. Now, as requested, here is my diagnostic build log:</p>
  
  <pre><code>1&gt;Project Performance Summary:
  1&gt;        3 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAll.App.Shared\OverAll.App.Shared.csproj   3 calls
  1&gt;                  1 ms  GetTargetPath                              1 calls
  1&gt;                  0 ms  GetNativeManifest                          1 calls
  1&gt;                  2 ms  GetCopyToOutputDirectoryItems              1 calls
  1&gt;        4 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAllField.XamarinAndroid.DataLayer\OverAllField.XamarinAndroid.DataLayer.csproj   3 calls
  1&gt;                  1 ms  GetTargetPath                              1 calls
  1&gt;                  0 ms  GetNativeManifest                          1 calls
  1&gt;                  3 ms  GetCopyToOutputDirectoryItems              1 calls
  1&gt;    40103 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAllField.XamarinAndroid.ServiceClient\OverAllField.XamarinAndroid.ServiceClient.csproj   1 calls
  1&gt;
  1&gt;Target Performance Summary:
  1&gt;        0 ms  Compile                                    1 calls
  1&gt;        0 ms  ResolveReferences                          1 calls
  1&gt;        0 ms  BclBuildGetTargetPath                      1 calls
  1&gt;        0 ms  EnsureNuGetPackageBuildImports             1 calls
  1&gt;        0 ms  AfterResGen                                1 calls
  1&gt;        0 ms  ResolveCodeAnalysisRuleSet                 1 calls
  1&gt;        0 ms  _CreatePropertiesCache                     1 calls
  1&gt;        0 ms  _SetTargetFrameworkMonikerAttribute        1 calls
  1&gt;        0 ms  BeforeResGen                               1 calls
  1&gt;        0 ms  ModifyUnitTestPlatformVersion              1 calls
  1&gt;        0 ms  CreateCustomManifestResourceNames          1 calls
  1&gt;        0 ms  BclBuildAddProjectReferenceProperties      1 calls
  1&gt;        0 ms  _ResolveMonoAndroidFramework               1 calls
  1&gt;        0 ms  UpdateAndroidResources                     1 calls
  1&gt;        0 ms  CoreBuild                                  1 calls
  1&gt;        0 ms  ExpressionBuildExtension                   1 calls
  1&gt;        0 ms  _CheckTargetFramework                      1 calls
  1&gt;        0 ms  _CopyAppConfigFile                         1 calls
  1&gt;        0 ms  Build                                      1 calls
  1&gt;        0 ms  DeleteBuildInfoFile                        1 calls
  1&gt;        0 ms  CleanXsdCodeGen                            1 calls
  1&gt;        0 ms  _SetupInstantRun                           1 calls
  1&gt;        0 ms  GetFrameworkPaths                          1 calls
  1&gt;        0 ms  DeleteBuildInfoResource                    1 calls
  1&gt;        0 ms  _AddAndroidDefines                         1 calls
  1&gt;        0 ms  BuildOnlySettings                          1 calls
  1&gt;        0 ms  ComputeIntermediateSatelliteAssemblies     1 calls
  1&gt;        0 ms  ValidationExtension                        1 calls
  1&gt;        0 ms  AfterCompile                               1 calls
  1&gt;        0 ms  _CheckInstantRunCondition                  1 calls
  1&gt;        0 ms  _GenerateSatelliteAssemblyInputs           1 calls
  1&gt;        0 ms  _SetupApplicationJavaClass                 1 calls
  1&gt;        0 ms  _SetupDesignTimeBuildForIntellisense       1 calls
  1&gt;        0 ms  SetWin32ManifestProperties                 1 calls
  1&gt;        0 ms  CreateSatelliteAssemblies                  1 calls
  1&gt;        0 ms  _CopySourceItemsToOutputDirectory          1 calls
  1&gt;        0 ms  GetInstalledSDKLocations                   1 calls
  1&gt;        0 ms  _AddAndroidEnvironmentToCompile            1 calls
  1&gt;        0 ms  _CheckForContent                           1 calls
  1&gt;        0 ms  _SeparateAppExtensionReferences            1 calls
  1&gt;        0 ms  AfterResolveReferences                     1 calls
  1&gt;        0 ms  BeforeResolveReferences                    1 calls
  1&gt;        0 ms  PrepareResources                           1 calls
  1&gt;        0 ms  ResolveSDKReferences                       1 calls
  1&gt;        0 ms  _CheckForDeletedResourceFile               1 calls
  1&gt;        0 ms  BeforeCompile                              1 calls
  1&gt;        0 ms  UpdateAndroidAssets                        1 calls
  1&gt;        0 ms  DesignTimeXamlMarkupCompilation            1 calls
  1&gt;        0 ms  _AddMultiDexDependencyJars                 1 calls
  1&gt;        0 ms  PrepareForRun                              1 calls
  1&gt;        0 ms  ResGen                                     1 calls
  1&gt;        0 ms  _GenerateAndroidAssetsDir                  1 calls
  1&gt;        0 ms  AfterBuild                                 1 calls
  1&gt;        0 ms  BclBuildSetRunningFullBuild                1 calls
  1&gt;        0 ms  GetNativeManifest                          2 calls
  1&gt;        0 ms  ExpandSDKReferences                        1 calls
  1&gt;        0 ms  GenerateTargetFrameworkMonikerAttribute    1 calls
  1&gt;        0 ms  _GenerateAndroidResourceDir                1 calls
  1&gt;        0 ms  CreateManifestResourceNames                1 calls
  1&gt;        0 ms  BeforeBuild                                1 calls
  1&gt;        0 ms  _GenerateCompileInputs                     1 calls
  1&gt;        0 ms  _SetupDesignTimeBuildForBuild              1 calls
  1&gt;        0 ms  PrepareResourceNames                       1 calls
  1&gt;        0 ms  _AddNativeLibraryArchiveToCompile          1 calls
  1&gt;        1 ms  GetCopyToOutputDirectoryXamlAppDefs        3 calls
  1&gt;        1 ms  _GenerateJavaDesignerForComponent          1 calls
  1&gt;        1 ms  _CollectMonoAndroidOutputs                 1 calls
  1&gt;        1 ms  _SetEmbeddedWin32ManifestProperties        1 calls
  1&gt;        1 ms  CoreResGen                                 1 calls
  1&gt;        1 ms  _ValidateLinkMode                          1 calls
  1&gt;        1 ms  _GetLibraryImports                         1 calls
  1&gt;        1 ms  _CheckForCompileOutputs                    1 calls
  1&gt;        1 ms  _ReadPropertiesCache                       1 calls
  1&gt;        1 ms  GetTargetPath                              2 calls
  1&gt;        1 ms  _ComputeAndroidResourcePaths               1 calls
  1&gt;        1 ms  SetBuildInfoDefaults                       1 calls
  1&gt;        1 ms  SplitResourcesByCulture                    1 calls
  1&gt;        1 ms  _SplitProjectReferencesByFileExistence     3 calls
  1&gt;        1 ms  GenerateCompiledExpressionsTempFile        1 calls
  1&gt;        1 ms  BclBuildDetermineReferencesToRedirect      1 calls
  1&gt;        1 ms  _GetReferenceAssemblyPaths                 1 calls
  1&gt;        1 ms  PreXsdCodeGen                              1 calls
  1&gt;        2 ms  _RegisterMdbFilesWithFileWrites            1 calls
  1&gt;        2 ms  PrepareForBuild                            1 calls
  1&gt;        2 ms  _BuildSdkCache                             1 calls
  1&gt;        2 ms  _CalculateAdditionalResourceCacheDirectories   1 calls
  1&gt;        2 ms  AssignProjectConfiguration                 1 calls
  1&gt;        2 ms  _CreateAdditionalResourceCache             1 calls
  1&gt;        2 ms  GetReferenceAssemblyPaths                  1 calls
  1&gt;        3 ms  _GetAdditionalResourcesFromAssemblies      1 calls
  1&gt;        3 ms  _CheckDuplicateJavaLibraries               1 calls
  1&gt;        3 ms  _CollectAdditionalResourceFiles            1 calls
  1&gt;        3 ms  _ExtractLibraryProjectImports              1 calls
  1&gt;        3 ms  _ComputeAndroidAssetsPaths                 1 calls
  1&gt;        3 ms  AssignTargetPaths                          3 calls
  1&gt;        3 ms  CopyFilesToOutputDirectory                 1 calls
  1&gt;        4 ms  _ValidateResourceCache                     1 calls
  1&gt;        4 ms  _ValidateAndroidPackageProperties          1 calls
  1&gt;        5 ms  IncrementalClean                           1 calls
  1&gt;        7 ms  _ResolveMonoAndroidSdks                    1 calls
  1&gt;        9 ms  _CheckForInvalidConfigurationAndPlatform   3 calls
  1&gt;       10 ms  GetCopyToOutputDirectoryItems              3 calls
  1&gt;       11 ms  _CopyFilesMarkedCopyLocal                  1 calls
  1&gt;       11 ms  _CleanGetCurrentAndPriorFileWrites         1 calls
  1&gt;       12 ms  _AddLibraryProjectsEmbeddedResourceToProject   1 calls
  1&gt;       18 ms  ImplicitlyExpandDesignTimeFacades          1 calls
  1&gt;       29 ms  _BuildLibraryImportsCache                  1 calls
  1&gt;       41 ms  ResolveProjectReferences                   1 calls
  1&gt;       70 ms  _SetLatestTargetFrameworkVersion           1 calls
  1&gt;      114 ms  _ResolveLibraryProjectImports              1 calls
  1&gt;      138 ms  ResolveAssemblyReferences                  1 calls
  1&gt;      207 ms  _UpdateAndroidResgen                       1 calls
  1&gt;      356 ms  _GetPrimaryCpuAbi                          1 calls
  1&gt;      803 ms  CoreCompile                                1 calls
  1&gt;    38202 ms  _BuildAdditionalResourcesCache             1 calls
  1&gt;
  1&gt;Task Performance Summary:
  1&gt;        0 ms  CreateCSharpManifestResourceName           1 calls
  1&gt;        0 ms  Delete                                     2 calls
  1&gt;        0 ms  FindAppConfigFile                          1 calls
  1&gt;        0 ms  ResolveCodeAnalysisRuleSet                 1 calls
  1&gt;        0 ms  CallTarget                                 1 calls
  1&gt;        0 ms  ResolveNonMSBuildProjectOutput             1 calls
  1&gt;        0 ms  AssignCulture                              1 calls
  1&gt;        1 ms  GetFrameworkPath                           1 calls
  1&gt;        1 ms  GetAndroidPackageName                      1 calls
  1&gt;        1 ms  AssignProjectConfiguration                 1 calls
  1&gt;        1 ms  ReadImportedLibrariesCache                 1 calls
  1&gt;        1 ms  ReadLinesFromFile                          2 calls
  1&gt;        1 ms  GetAppSettingsDirectory                    1 calls
  1&gt;        1 ms  AssignTargetPath                          18 calls
  1&gt;        1 ms  CreateTemporaryDirectory                   1 calls
  1&gt;        1 ms  GetReferenceAssemblyPaths                  2 calls
  1&gt;        2 ms  Message                                   20 calls
  1&gt;        2 ms  CalculateAdditionalResourceCacheDirectories   1 calls
  1&gt;        2 ms  GetJavaPlatformJar                         1 calls
  1&gt;        2 ms  MakeDir                                    2 calls
  1&gt;        2 ms  WriteLinesToFile                           1 calls
  1&gt;        2 ms  ConvertToAbsolutePath                      1 calls
  1&gt;        3 ms  RemoveDuplicates                           2 calls
  1&gt;        3 ms  CopyIfChanged                              1 calls
  1&gt;        3 ms  CheckDuplicateJavaLibraries                1 calls
  1&gt;        3 ms  AndroidComputeResPaths                     2 calls
  1&gt;        3 ms  ReadLibraryProjectImportsCache             1 calls
  1&gt;        3 ms  CreateProperty                            41 calls
  1&gt;        4 ms  CopyGeneratedJavaResourceClasses           1 calls
  1&gt;        4 ms  GetExtraPackages                           1 calls
  1&gt;        4 ms  GetAndroidDefineConstants                  1 calls
  1&gt;        4 ms  CreateAndroidResourceStamp                 1 calls
  1&gt;        5 ms  FindUnderPath                              5 calls
  1&gt;        5 ms  ReadAdditionalResourcesFromAssemblyCache   2 calls
  1&gt;        5 ms  CreateResgenManifest                       1 calls
  1&gt;        6 ms  CreateItem                                23 calls
  1&gt;        6 ms  RemoveDirFixed                             1 calls
  1&gt;       12 ms  CreateManagedLibraryResourceArchive        1 calls
  1&gt;       14 ms  Copy                                       3 calls
  1&gt;       16 ms  ConvertResourcesCases                      1 calls
  1&gt;       21 ms  GenerateResourceDesigner                   1 calls
  1&gt;       28 ms  GetImportedLibraries                       1 calls
  1&gt;       49 ms  MSBuild                                    3 calls
  1&gt;       49 ms  ReadResolvedSdksCache                      1 calls
  1&gt;      114 ms  ResolveLibraryProjectImports               1 calls
  1&gt;      137 ms  ResolveAssemblyReference                   1 calls
  1&gt;      142 ms  Aapt                                       1 calls
  1&gt;      347 ms  GetPrimaryCpuAbi                           1 calls
  1&gt;      792 ms  Csc                                        1 calls
  1&gt;    38201 ms  GetAdditionalResourcesFromAssemblies       1 calls
  1&gt;
  1&gt;Build succeeded.
  1&gt;
  1&gt;Time Elapsed 00:00:40.09
  </code></pre>
  
  <p>There is a second summary (the log has 2 of these summaries somehow), but I can't include it in the question, because it would exceed the body character limit.
  Smaller version of the second summary:</p>
  
  <pre><code>2&gt;Project Performance Summary:
  2&gt;        6 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAll.App.Shared\OverAll.App.Shared.csproj   5 calls
  2&gt;                  0 ms  GetTargetPath                              1 calls
  2&gt;                  0 ms  GetNativeManifest                          1 calls
  2&gt;                  1 ms  GetCopyToOutputDirectoryItems              1 calls
  2&gt;                  5 ms  GetBuiltProjectOutputRecursive             2 calls
  2&gt;        9 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAllField.XamarinAndroid.BarcodeScanner\OverAllField.XamarinAndroid.BarcodeScanner.csproj   4 calls
  2&gt;                  0 ms  GetTargetPath                              1 calls
  2&gt;                  2 ms  GetNativeManifest                          1 calls
  2&gt;                  3 ms  GetCopyToOutputDirectoryItems              1 calls
  2&gt;                  4 ms  GetBuiltProjectOutputRecursive             1 calls
  2&gt;       17 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAllField.XamarinAndroid.DataLayer\OverAllField.XamarinAndroid.DataLayer.csproj   5 calls
  2&gt;                  9 ms  GetTargetPath                              1 calls
  2&gt;                  1 ms  GetNativeManifest                          1 calls
  2&gt;                  2 ms  GetCopyToOutputDirectoryItems              1 calls
  2&gt;                  5 ms  GetBuiltProjectOutputRecursive             2 calls
  2&gt;       46 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAllField.XamarinAndroid.ServiceClient\OverAllField.XamarinAndroid.ServiceClient.csproj   4 calls
  2&gt;                 21 ms  GetTargetPath                              1 calls
  2&gt;                  0 ms  GetNativeManifest                          1 calls
  2&gt;                  2 ms  GetCopyToOutputDirectoryItems              1 calls
  2&gt;                 23 ms  GetBuiltProjectOutputRecursive             1 calls
  2&gt;    87736 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAllField.Android\OverAllField.XamarinAndroid.csproj   1 calls
  </code></pre>
  
  <p>Second Target Performance Summary: (removed anything &lt;1000 ms to reduce chars)</p>
  
  <pre><code>2&gt;     1955 ms  _GenerateJavaStubs                         1 calls
  2&gt;     3083 ms  _CreateBaseApk                             1 calls
  2&gt;     3467 ms  _UpdateAndroidResgen                       1 calls
  2&gt;     8944 ms  _CompileToDalvikWithDx                     1 calls
  2&gt;    66321 ms  _BuildAdditionalResourcesCache             1 calls
  </code></pre>
  
  <p>Second Task Performance Summary: (again, removed anything &lt;1000 ms to reduce chars)</p>
  
  <pre><code>2&gt;     1245 ms  GenerateJavaStubs                          1 calls
  2&gt;     2334 ms  ConvertResourcesCases                      3 calls
  2&gt;     4637 ms  Aapt                                       2 calls
  2&gt;     8941 ms  CompileToDalvik                            1 calls
  2&gt;    66320 ms  GetAdditionalResourcesFromAssemblies       1 calls
  2&gt;
  2&gt;Build succeeded.
  2&gt;
  2&gt;Time Elapsed 00:01:27.73
  </code></pre>
  
  <p>Full diagnostic build log <a href="https://www.dropbox.com/s/7kbvfipx1hnv31l/app-build-diagnostic-log.txt?dl=0">here</a></p>
  
  <p><strong>UPDATE 4</strong></p>
  
  <p>Full diagnostic build log with Android support version 23 <a href="https://www.dropbox.com/s/n2t8fno0oo73q9h/app-build-diagnostic-log-support-23.txt?dl=0">here</a></p>
  
  <p>There is a significant difference between the build times.
  Support version 24:</p>
  
  <pre><code>1&gt;Project Performance Summary:
  1&gt;    40103 ms  C:\Development\Apps\trunk\App.Droid\App.Droid.ServiceClient\App.Droid.ServiceClient.csproj   1 calls
  ...
  2&gt;Project Performance Summary:
  2&gt;    87736 ms  C:\Development\Apps\trunk\App.Droid\App.Droid\App.Droid.csproj   1 calls
  </code></pre>
  
  <p>Support version 23:</p>
  
  <pre><code>1&gt;Project Performance Summary:
  1&gt;      962 ms  C:\Development\Apps\trunk-r1029\App.Droid\App.Droid.ServiceClient\App.Droid.ServiceClient.csproj   1 calls
  2&gt;Project Performance Summary:
  2&gt;    18214 ms  C:\Development\Apps\trunk-r1029\App.Droid\App.Droid\App.Droid.csproj   1 calls
  </code></pre>
  
  <p>Both are built with target Android 7.0 and the same Xamarin version, the only difference is the Android Support library version. Isn't that a huge increase?</p>
  
  <p>Thanks in advance!</p>