21

The build/deploy of my Xamarin.Android app is painfully slow these days. I cannot remember it being this slow before.

I have enabled:

  • Use shared runtime
  • Fast deployment

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.

Why could this be so extremely slow? Am I not using the right settings?

UPDATE 2

Yesterday (november 14th) I updated Xamarin.VS to 4.2.1.58. No improvements in build duration.

We are using TeamCity to build release versions of our app, the TeamCity statistics show perfectly what I'm talking about.

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.

Nov. 7, before installing latest Xamarin update Nov. 8, after installing update and targetting Android 7

UPDATE 3

Jon, thanks for your help.

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 GetAdditionalResourcesFromAssemblies takes a lot of time.

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..

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...

So:

  • It's probably not the VS Xamarin update (else revision 1029 would build slow as well)
  • It's probably not fast deployment, the duration increased in the build process

So what was changed between revision 1029 and 1030 of my app?

  1. Updated Xamarin for Visual Studio to 4.2.0.719
  2. Installed Android 7.0 SDK platform in Android SDK Manager
  3. Changed Compile using Android version to Android 7.0 in project properties
  4. Updated Xamarin.Android Support Libraries from 23.4.0.1 to 24.2.1

Change 4 was why I updated in the first place, I wanted to use Bottomsheet, 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.

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 this in the Xamarin forum. Setting AndroidExplicitCrunch build property to true seems to fix it there, but when I tried that, I got another build error.

Anyway, that's what I've tried in the meantime. Now, as requested, here is my diagnostic build log:

1>Project Performance Summary:
1>        3 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAll.App.Shared\OverAll.App.Shared.csproj   3 calls
1>                  1 ms  GetTargetPath                              1 calls
1>                  0 ms  GetNativeManifest                          1 calls
1>                  2 ms  GetCopyToOutputDirectoryItems              1 calls
1>        4 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAllField.XamarinAndroid.DataLayer\OverAllField.XamarinAndroid.DataLayer.csproj   3 calls
1>                  1 ms  GetTargetPath                              1 calls
1>                  0 ms  GetNativeManifest                          1 calls
1>                  3 ms  GetCopyToOutputDirectoryItems              1 calls
1>    40103 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAllField.XamarinAndroid.ServiceClient\OverAllField.XamarinAndroid.ServiceClient.csproj   1 calls
1>
1>Target Performance Summary:
1>        0 ms  Compile                                    1 calls
1>        0 ms  ResolveReferences                          1 calls
1>        0 ms  BclBuildGetTargetPath                      1 calls
1>        0 ms  EnsureNuGetPackageBuildImports             1 calls
1>        0 ms  AfterResGen                                1 calls
1>        0 ms  ResolveCodeAnalysisRuleSet                 1 calls
1>        0 ms  _CreatePropertiesCache                     1 calls
1>        0 ms  _SetTargetFrameworkMonikerAttribute        1 calls
1>        0 ms  BeforeResGen                               1 calls
1>        0 ms  ModifyUnitTestPlatformVersion              1 calls
1>        0 ms  CreateCustomManifestResourceNames          1 calls
1>        0 ms  BclBuildAddProjectReferenceProperties      1 calls
1>        0 ms  _ResolveMonoAndroidFramework               1 calls
1>        0 ms  UpdateAndroidResources                     1 calls
1>        0 ms  CoreBuild                                  1 calls
1>        0 ms  ExpressionBuildExtension                   1 calls
1>        0 ms  _CheckTargetFramework                      1 calls
1>        0 ms  _CopyAppConfigFile                         1 calls
1>        0 ms  Build                                      1 calls
1>        0 ms  DeleteBuildInfoFile                        1 calls
1>        0 ms  CleanXsdCodeGen                            1 calls
1>        0 ms  _SetupInstantRun                           1 calls
1>        0 ms  GetFrameworkPaths                          1 calls
1>        0 ms  DeleteBuildInfoResource                    1 calls
1>        0 ms  _AddAndroidDefines                         1 calls
1>        0 ms  BuildOnlySettings                          1 calls
1>        0 ms  ComputeIntermediateSatelliteAssemblies     1 calls
1>        0 ms  ValidationExtension                        1 calls
1>        0 ms  AfterCompile                               1 calls
1>        0 ms  _CheckInstantRunCondition                  1 calls
1>        0 ms  _GenerateSatelliteAssemblyInputs           1 calls
1>        0 ms  _SetupApplicationJavaClass                 1 calls
1>        0 ms  _SetupDesignTimeBuildForIntellisense       1 calls
1>        0 ms  SetWin32ManifestProperties                 1 calls
1>        0 ms  CreateSatelliteAssemblies                  1 calls
1>        0 ms  _CopySourceItemsToOutputDirectory          1 calls
1>        0 ms  GetInstalledSDKLocations                   1 calls
1>        0 ms  _AddAndroidEnvironmentToCompile            1 calls
1>        0 ms  _CheckForContent                           1 calls
1>        0 ms  _SeparateAppExtensionReferences            1 calls
1>        0 ms  AfterResolveReferences                     1 calls
1>        0 ms  BeforeResolveReferences                    1 calls
1>        0 ms  PrepareResources                           1 calls
1>        0 ms  ResolveSDKReferences                       1 calls
1>        0 ms  _CheckForDeletedResourceFile               1 calls
1>        0 ms  BeforeCompile                              1 calls
1>        0 ms  UpdateAndroidAssets                        1 calls
1>        0 ms  DesignTimeXamlMarkupCompilation            1 calls
1>        0 ms  _AddMultiDexDependencyJars                 1 calls
1>        0 ms  PrepareForRun                              1 calls
1>        0 ms  ResGen                                     1 calls
1>        0 ms  _GenerateAndroidAssetsDir                  1 calls
1>        0 ms  AfterBuild                                 1 calls
1>        0 ms  BclBuildSetRunningFullBuild                1 calls
1>        0 ms  GetNativeManifest                          2 calls
1>        0 ms  ExpandSDKReferences                        1 calls
1>        0 ms  GenerateTargetFrameworkMonikerAttribute    1 calls
1>        0 ms  _GenerateAndroidResourceDir                1 calls
1>        0 ms  CreateManifestResourceNames                1 calls
1>        0 ms  BeforeBuild                                1 calls
1>        0 ms  _GenerateCompileInputs                     1 calls
1>        0 ms  _SetupDesignTimeBuildForBuild              1 calls
1>        0 ms  PrepareResourceNames                       1 calls
1>        0 ms  _AddNativeLibraryArchiveToCompile          1 calls
1>        1 ms  GetCopyToOutputDirectoryXamlAppDefs        3 calls
1>        1 ms  _GenerateJavaDesignerForComponent          1 calls
1>        1 ms  _CollectMonoAndroidOutputs                 1 calls
1>        1 ms  _SetEmbeddedWin32ManifestProperties        1 calls
1>        1 ms  CoreResGen                                 1 calls
1>        1 ms  _ValidateLinkMode                          1 calls
1>        1 ms  _GetLibraryImports                         1 calls
1>        1 ms  _CheckForCompileOutputs                    1 calls
1>        1 ms  _ReadPropertiesCache                       1 calls
1>        1 ms  GetTargetPath                              2 calls
1>        1 ms  _ComputeAndroidResourcePaths               1 calls
1>        1 ms  SetBuildInfoDefaults                       1 calls
1>        1 ms  SplitResourcesByCulture                    1 calls
1>        1 ms  _SplitProjectReferencesByFileExistence     3 calls
1>        1 ms  GenerateCompiledExpressionsTempFile        1 calls
1>        1 ms  BclBuildDetermineReferencesToRedirect      1 calls
1>        1 ms  _GetReferenceAssemblyPaths                 1 calls
1>        1 ms  PreXsdCodeGen                              1 calls
1>        2 ms  _RegisterMdbFilesWithFileWrites            1 calls
1>        2 ms  PrepareForBuild                            1 calls
1>        2 ms  _BuildSdkCache                             1 calls
1>        2 ms  _CalculateAdditionalResourceCacheDirectories   1 calls
1>        2 ms  AssignProjectConfiguration                 1 calls
1>        2 ms  _CreateAdditionalResourceCache             1 calls
1>        2 ms  GetReferenceAssemblyPaths                  1 calls
1>        3 ms  _GetAdditionalResourcesFromAssemblies      1 calls
1>        3 ms  _CheckDuplicateJavaLibraries               1 calls
1>        3 ms  _CollectAdditionalResourceFiles            1 calls
1>        3 ms  _ExtractLibraryProjectImports              1 calls
1>        3 ms  _ComputeAndroidAssetsPaths                 1 calls
1>        3 ms  AssignTargetPaths                          3 calls
1>        3 ms  CopyFilesToOutputDirectory                 1 calls
1>        4 ms  _ValidateResourceCache                     1 calls
1>        4 ms  _ValidateAndroidPackageProperties          1 calls
1>        5 ms  IncrementalClean                           1 calls
1>        7 ms  _ResolveMonoAndroidSdks                    1 calls
1>        9 ms  _CheckForInvalidConfigurationAndPlatform   3 calls
1>       10 ms  GetCopyToOutputDirectoryItems              3 calls
1>       11 ms  _CopyFilesMarkedCopyLocal                  1 calls
1>       11 ms  _CleanGetCurrentAndPriorFileWrites         1 calls
1>       12 ms  _AddLibraryProjectsEmbeddedResourceToProject   1 calls
1>       18 ms  ImplicitlyExpandDesignTimeFacades          1 calls
1>       29 ms  _BuildLibraryImportsCache                  1 calls
1>       41 ms  ResolveProjectReferences                   1 calls
1>       70 ms  _SetLatestTargetFrameworkVersion           1 calls
1>      114 ms  _ResolveLibraryProjectImports              1 calls
1>      138 ms  ResolveAssemblyReferences                  1 calls
1>      207 ms  _UpdateAndroidResgen                       1 calls
1>      356 ms  _GetPrimaryCpuAbi                          1 calls
1>      803 ms  CoreCompile                                1 calls
1>    38202 ms  _BuildAdditionalResourcesCache             1 calls
1>
1>Task Performance Summary:
1>        0 ms  CreateCSharpManifestResourceName           1 calls
1>        0 ms  Delete                                     2 calls
1>        0 ms  FindAppConfigFile                          1 calls
1>        0 ms  ResolveCodeAnalysisRuleSet                 1 calls
1>        0 ms  CallTarget                                 1 calls
1>        0 ms  ResolveNonMSBuildProjectOutput             1 calls
1>        0 ms  AssignCulture                              1 calls
1>        1 ms  GetFrameworkPath                           1 calls
1>        1 ms  GetAndroidPackageName                      1 calls
1>        1 ms  AssignProjectConfiguration                 1 calls
1>        1 ms  ReadImportedLibrariesCache                 1 calls
1>        1 ms  ReadLinesFromFile                          2 calls
1>        1 ms  GetAppSettingsDirectory                    1 calls
1>        1 ms  AssignTargetPath                          18 calls
1>        1 ms  CreateTemporaryDirectory                   1 calls
1>        1 ms  GetReferenceAssemblyPaths                  2 calls
1>        2 ms  Message                                   20 calls
1>        2 ms  CalculateAdditionalResourceCacheDirectories   1 calls
1>        2 ms  GetJavaPlatformJar                         1 calls
1>        2 ms  MakeDir                                    2 calls
1>        2 ms  WriteLinesToFile                           1 calls
1>        2 ms  ConvertToAbsolutePath                      1 calls
1>        3 ms  RemoveDuplicates                           2 calls
1>        3 ms  CopyIfChanged                              1 calls
1>        3 ms  CheckDuplicateJavaLibraries                1 calls
1>        3 ms  AndroidComputeResPaths                     2 calls
1>        3 ms  ReadLibraryProjectImportsCache             1 calls
1>        3 ms  CreateProperty                            41 calls
1>        4 ms  CopyGeneratedJavaResourceClasses           1 calls
1>        4 ms  GetExtraPackages                           1 calls
1>        4 ms  GetAndroidDefineConstants                  1 calls
1>        4 ms  CreateAndroidResourceStamp                 1 calls
1>        5 ms  FindUnderPath                              5 calls
1>        5 ms  ReadAdditionalResourcesFromAssemblyCache   2 calls
1>        5 ms  CreateResgenManifest                       1 calls
1>        6 ms  CreateItem                                23 calls
1>        6 ms  RemoveDirFixed                             1 calls
1>       12 ms  CreateManagedLibraryResourceArchive        1 calls
1>       14 ms  Copy                                       3 calls
1>       16 ms  ConvertResourcesCases                      1 calls
1>       21 ms  GenerateResourceDesigner                   1 calls
1>       28 ms  GetImportedLibraries                       1 calls
1>       49 ms  MSBuild                                    3 calls
1>       49 ms  ReadResolvedSdksCache                      1 calls
1>      114 ms  ResolveLibraryProjectImports               1 calls
1>      137 ms  ResolveAssemblyReference                   1 calls
1>      142 ms  Aapt                                       1 calls
1>      347 ms  GetPrimaryCpuAbi                           1 calls
1>      792 ms  Csc                                        1 calls
1>    38201 ms  GetAdditionalResourcesFromAssemblies       1 calls
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:40.09

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:

2>Project Performance Summary:
2>        6 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAll.App.Shared\OverAll.App.Shared.csproj   5 calls
2>                  0 ms  GetTargetPath                              1 calls
2>                  0 ms  GetNativeManifest                          1 calls
2>                  1 ms  GetCopyToOutputDirectoryItems              1 calls
2>                  5 ms  GetBuiltProjectOutputRecursive             2 calls
2>        9 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAllField.XamarinAndroid.BarcodeScanner\OverAllField.XamarinAndroid.BarcodeScanner.csproj   4 calls
2>                  0 ms  GetTargetPath                              1 calls
2>                  2 ms  GetNativeManifest                          1 calls
2>                  3 ms  GetCopyToOutputDirectoryItems              1 calls
2>                  4 ms  GetBuiltProjectOutputRecursive             1 calls
2>       17 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAllField.XamarinAndroid.DataLayer\OverAllField.XamarinAndroid.DataLayer.csproj   5 calls
2>                  9 ms  GetTargetPath                              1 calls
2>                  1 ms  GetNativeManifest                          1 calls
2>                  2 ms  GetCopyToOutputDirectoryItems              1 calls
2>                  5 ms  GetBuiltProjectOutputRecursive             2 calls
2>       46 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAllField.XamarinAndroid.ServiceClient\OverAllField.XamarinAndroid.ServiceClient.csproj   4 calls
2>                 21 ms  GetTargetPath                              1 calls
2>                  0 ms  GetNativeManifest                          1 calls
2>                  2 ms  GetCopyToOutputDirectoryItems              1 calls
2>                 23 ms  GetBuiltProjectOutputRecursive             1 calls
2>    87736 ms  C:\Development\Apps\FieldService-trunk\OverAllField.XamarinAndroid\OverAllField.Android\OverAllField.XamarinAndroid.csproj   1 calls

Second Target Performance Summary: (removed anything <1000 ms to reduce chars)

2>     1955 ms  _GenerateJavaStubs                         1 calls
2>     3083 ms  _CreateBaseApk                             1 calls
2>     3467 ms  _UpdateAndroidResgen                       1 calls
2>     8944 ms  _CompileToDalvikWithDx                     1 calls
2>    66321 ms  _BuildAdditionalResourcesCache             1 calls

Second Task Performance Summary: (again, removed anything <1000 ms to reduce chars)

2>     1245 ms  GenerateJavaStubs                          1 calls
2>     2334 ms  ConvertResourcesCases                      3 calls
2>     4637 ms  Aapt                                       2 calls
2>     8941 ms  CompileToDalvik                            1 calls
2>    66320 ms  GetAdditionalResourcesFromAssemblies       1 calls
2>
2>Build succeeded.
2>
2>Time Elapsed 00:01:27.73

Full diagnostic build log here

UPDATE 4

Full diagnostic build log with Android support version 23 here

There is a significant difference between the build times. Support version 24:

1>Project Performance Summary:
1>    40103 ms  C:\Development\Apps\trunk\App.Droid\App.Droid.ServiceClient\App.Droid.ServiceClient.csproj   1 calls
...
2>Project Performance Summary:
2>    87736 ms  C:\Development\Apps\trunk\App.Droid\App.Droid\App.Droid.csproj   1 calls

Support version 23:

1>Project Performance Summary:
1>      962 ms  C:\Development\Apps\trunk-r1029\App.Droid\App.Droid.ServiceClient\App.Droid.ServiceClient.csproj   1 calls
2>Project Performance Summary:
2>    18214 ms  C:\Development\Apps\trunk-r1029\App.Droid\App.Droid\App.Droid.csproj   1 calls

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?

Thanks in advance!

avb
  • 1,558
  • 1
  • 14
  • 37
  • So the `Target` of `_BuildAdditionalResourcesCache` is taking forever. Which may run the `Task` of `GetAdditionalResourcesFromAssemblies`. I believe what is happening here potentially is that when you upgraded to the Android Support libs, it needed to download and cache the latest version. I would suspect that new builds will be less time as well? I would need a full diagnostic build output to see the internals of that `Task`. Please feel free to upload that. – Jon Douglas Nov 15 '16 at 19:13
  • Ok, that would explain the increase. It's not just the first build that's this slow though, I have built the app hundreds of times since November 8th (developing the app), and unfortunately it still takes 3 minutes or more to build and deploy. I'll try to upload the full build log in a minute – avb Nov 15 '16 at 19:23
  • Just added the full build log to the question. Thanks for your time – avb Nov 15 '16 at 19:57
  • Please see my Edit – Jon Douglas Nov 15 '16 at 20:43
  • So have you managed to get the answer? I got this issue after updating target framework from API 20 to API 24 and build tools from 23x to 25. Xamarin sample app with only v7 AppCompat package added takes 1.5 min to build on my machine with `49124 ms GetAdditionalResourcesFromAssemblies 1 calls` record in the diagnostic log. – Mikhail Nov 17 '16 at 11:16
  • Looks like the reason is here https://github.com/xamarin/xamarin-android/pull/292 but I'm not sure how it is related to support library update unless this task does re-hashing for every assembly and number of assemblies had increased with update. – Mikhail Nov 17 '16 at 11:50
  • @Mikhail No, I didn't find the answer. Jon's answer says it's the `GetAdditionalResourcesFromAssemblies` task which the team is working on right now, my thought is it's not just that.. Anyway, I just updated the question, added a build log for v23 support. It's a lot faster. Let's hope Jon finds anything. – avb Nov 17 '16 at 12:38
  • Sadly there's no "single issue" that resolves all of this. As mentioned in my answer, the culprit is `GetAdditionalResourcesFromAssemblies` and as you can see from the PR I linked and @Mikhail linked, there is work being done to resolve this. I have updated my answer to reflect the other PR. – Jon Douglas Nov 17 '16 at 15:29
  • @avb Are you using the fix for this yet? It seems there's a fix (https://github.com/xamarin/xamarin-android/commit/2f690ca7d0c18055b01649de19b596df1626d3e2) that's not yet in the stable, but is in beta/alpha channel. I'm wondering if you're using it and how "stable" the beta/alpha is with it. – LampShade Feb 08 '17 at 18:10
  • @LampShade I'm not using the alpha or beta version of Xamarin so I don't know if this is fixed. What brought down rebuild performance to <10 secs was dropping ModernHttpClient. Somehow rebuild went down from 4 mins to that... Initial build is still slow though. Tried several times by including the lib again to make sure, but same results. Somehow it was ModernHttpClient that broke rebuild performance for me... – avb Feb 08 '17 at 19:56
  • @avb Which one are you referring to as modern? here is what I see http://i.imgur.com/LNj3rn5.png – LampShade Feb 08 '17 at 20:28
  • @LampShade ModernHttpClient is a custom http client handler that uses the native Android stack via OkHttp instead of the default Mono. See https://components.xamarin.com/view/modernhttpclient – avb Feb 08 '17 at 20:55
  • @avb Ok, I see. So I was quoted this on my bugzilla "What is happening is the .sha1 hash is being calculated every build to check for zip integrity. The fix is to cache the hash. Note this will only effect the latest Support library nuget packages as they were the first release to include a SHA which the build system could check against. As mentioned the latest Alpha has the fix. Once the sha1 has been calculated and cached it will be used after that. ". So it's possible for you that by removing the package, there were less repeated calculations done. – LampShade Feb 08 '17 at 21:05
  • @LampShade "Note this will only effect the latest Support library nuget packages as they were the first release to include a SHA which the build system could check against." Ah that quote clears all misunderstandings for me. So that's why the build time slowed down after updating the NuGet package back then. Now I get JonDouglas's answer.. Never understood why this wouldn't be an issue before updating the support libraries. – avb Feb 08 '17 at 21:32
  • 1
    @avb So I updated to the beta channel of Xamarin Studio. My build time went from 10-15 minutes to less than 1 minute! I highly suggest switching to beta channel. Building after a full clean is still slow, but if you make 1 change then build again, it's wicked fast now. – LampShade Feb 09 '17 at 01:05
  • @LampShade great, thanks – avb Feb 09 '17 at 07:09
  • 1
    Did you ever find a solution that makes Xamarin.Forms feasible from a business perspective? It's October 2018 and I'm waiting 2~3 minutes to see my code changes on the emulator(s)/device(s) – Noobie3001 Oct 12 '18 at 14:40

1 Answers1

8

Although this is a very "tough" question to answer as build times can be dependent on many different factors, I can walk you through ways to determine what in your build is causing the delay. In most cases it's typically because of non-optimized Resources. This can be resources like raw images/audio/video that really should be optimized for mobile.

As for the experimental functionality you mentioned, you can view the release notes here:

https://developer.xamarin.com/releases/android/xamarin.android_7/xamarin.android_7.0/#Improved_Fast_Deployment

Note: This is experimental, thus it does not guarantee it will be stable enough to use in production.

As for Build Times, we need to know where the bottleneck is within your project. To do this, you need to enable Diagnostic Build Output in your build-agent's command. This is pretty simple with MSBuild via:

/v:diag or /verbosity:diagnostic (Or whatever combination you wanted)

and

/clp:PerformanceSummary - Which will tell use the performance timings of each task

https://msdn.microsoft.com/en-us/library/ms164311.aspx

EX: Building a File->New Android Project:

1>Project Performance Summary:
1>     4087 ms  c:\users\dougl\documents\visual studio 2015\Projects\App26\App26\App26.csproj   1 calls
1>               4087 ms  Rebuild                                    1 calls
1>
1>Target Performance Summary:
1>        0 ms  GetCopyToOutputDirectoryXamlAppDefs        1 calls
1>        0 ms  BeforeRebuild                              1 calls
1>        0 ms  PrepareResources                           1 calls
1>        0 ms  _DefineBuildTargetAbis                     1 calls
1>        0 ms  UpdateAndroidAssets                        1 calls
1>        0 ms  AfterBuild                                 1 calls
1>        0 ms  AfterCompile                               1 calls
1>        0 ms  BeforeCompile                              1 calls
1>        0 ms  ExpressionBuildExtension                   1 calls
1>        0 ms  _GenerateCompileInputs                     1 calls
1>        0 ms  ResolveCodeAnalysisRuleSet                 1 calls
1>        0 ms  _LinkAssemblies                            1 calls
1>        0 ms  GetTargetPath                              1 calls
1>        0 ms  Build                                      1 calls
1>        0 ms  GenerateCompiledExpressionsTempFile        1 calls
1>        0 ms  _CopyConfigFiles                           1 calls
1>        0 ms  Compile                                    1 calls
1>        0 ms  Rebuild                                    1 calls
1>        0 ms  ModifyUnitTestPlatformVersion              1 calls
1>        0 ms  _RegisterMdbFilesWithFileWrites            1 calls
1>        0 ms  _CheckForCompileOutputs                    1 calls
1>        0 ms  _SetupDesignTimeBuildForIntellisense       1 calls
1>        0 ms  _SetTargetFrameworkMonikerAttribute        1 calls
1>        0 ms  _GenerateAndroidAssetsDir                  1 calls
1>        0 ms  _AddMultiDexDependencyJars                 1 calls
1>        0 ms  AfterResolveReferences                     1 calls
1>        0 ms  UpdateAndroidResources                     1 calls
1>        0 ms  _CheckInstantRunCondition                  1 calls
1>        0 ms  CleanPublishFolder                         1 calls
1>        0 ms  _CheckTargetFramework                      1 calls
1>        0 ms  _CollectMonoAndroidOutputs                 1 calls
1>        0 ms  _CopySourceItemsToOutputDirectory          1 calls
1>        0 ms  CompileRdlFiles                            1 calls
1>        0 ms  _CreateAdditionalResourceCache             4 calls
1>        0 ms  DesignTimeXamlMarkupCompilation            1 calls
1>        0 ms  AfterRebuild                               1 calls
1>        0 ms  _SeparateAppExtensionReferences            1 calls
1>        0 ms  ExpandSDKReferences                        1 calls
1>        0 ms  _ReadPropertiesCache                       1 calls
1>        0 ms  AfterResGen                                1 calls
1>        0 ms  CleanReferencedProjects                    1 calls
1>        0 ms  _CollectPCLPdbFiles                        1 calls
1>        0 ms  Clean                                      1 calls
1>        0 ms  SetWin32ManifestProperties                 1 calls
1>        0 ms  ResolveSDKReferences                       1 calls
1>        0 ms  CreateSatelliteAssemblies                  1 calls
1>        0 ms  DeleteBuildInfoResource                    1 calls
1>        0 ms  _ResolveMonoAndroidFramework               1 calls
1>        0 ms  PrepareResourceNames                       1 calls
1>        0 ms  _SetupInstantRun                           1 calls
1>        0 ms  _SetupDesignTimeBuildForBuild              1 calls
1>        0 ms  CoreBuild                                  1 calls
1>        0 ms  _CheckForDeletedResourceFile               1 calls
1>        0 ms  GetFrameworkPaths                          1 calls
1>        0 ms  _ValidateLinkMode                          1 calls
1>        0 ms  DeleteBuildInfoFile                        1 calls
1>        0 ms  _CollectPCLMdbFiles                        1 calls
1>        0 ms  _CompileDex                                1 calls
1>        0 ms  GetInstalledSDKLocations                   1 calls
1>        0 ms  BeforeClean                                1 calls
1>        0 ms  BuildOnlySettings                          1 calls
1>        0 ms  _ValidateResourceCache                     1 calls
1>        0 ms  BeforeResolveReferences                    1 calls
1>        0 ms  _CheckForContent                           1 calls
1>        0 ms  BeforeResGen                               1 calls
1>        0 ms  PrepareRdlFiles                            1 calls
1>        0 ms  AfterClean                                 1 calls
1>        0 ms  _SetupApplicationJavaClass                 1 calls
1>        0 ms  ValidationExtension                        1 calls
1>        0 ms  _IncludeInstanceRunReference               1 calls
1>        0 ms  ResolveReferences                          1 calls
1>        0 ms  CreateCustomManifestResourceNames          1 calls
1>        0 ms  ResGen                                     1 calls
1>        0 ms  BeforeBuild                                1 calls
1>        1 ms  _SplitProjectReferencesByFileExistence     1 calls
1>        1 ms  _GenerateSatelliteAssemblyInputs           1 calls
1>        1 ms  PrepareForRun                              1 calls
1>        1 ms  CleanXsdCodeGen                            1 calls
1>        1 ms  GenerateTargetFrameworkMonikerAttribute    1 calls
1>        1 ms  ResolveProjectReferences                   1 calls
1>        1 ms  AssignTargetPaths                          1 calls
1>        1 ms  _CreateIntermediateAssembliesDir           1 calls
1>        1 ms  GetCopyToOutputDirectoryItems              1 calls
1>        1 ms  PreXsdCodeGen                              1 calls
1>        1 ms  _GetReferenceAssemblyPaths                 1 calls
1>        1 ms  CoreResGen                                 1 calls
1>        1 ms  _CleanGeneratedDeploymentFiles             1 calls
1>        1 ms  SetBuildInfoDefaults                       1 calls
1>        1 ms  AssignProjectConfiguration                 1 calls
1>        1 ms  _CreatePackageWorkspace                    1 calls
1>        1 ms  _GetMonoPlatformJarPath                    1 calls
1>        1 ms  PrepareForBuild                            1 calls
1>        1 ms  _CalculateAdditionalResourceCacheDirectories   1 calls
1>        1 ms  _ComputeAndroidResourcePaths               1 calls
1>        1 ms  _SetEmbeddedWin32ManifestProperties        1 calls
1>        1 ms  _GetAddOnPlatformLibraries                 1 calls
1>        1 ms  _GetLibraryImports                         1 calls
1>        1 ms  SplitResourcesByCulture                    1 calls
1>        1 ms  GetReferenceAssemblyPaths                  1 calls
1>        1 ms  _CheckProjectItems                         1 calls
1>        1 ms  _AdjustJavacVersionArguments               1 calls
1>        1 ms  _CleanGeneratedDebuggingFiles              1 calls
1>        2 ms  _PrepareAssemblies                         1 calls
1>        2 ms  _FindJavaStubFiles                         1 calls
1>        2 ms  _ExtractLibraryProjectImports              1 calls
1>        2 ms  _StripEmbeddedLibraries                    1 calls
1>        2 ms  _CleanGetCurrentAndPriorFileWrites         1 calls
1>        2 ms  _GetAdditionalResourcesFromAssemblies      1 calls
1>        2 ms  _FindCompiledJavaFiles                     1 calls
1>        2 ms  _CheckDuplicateJavaLibraries               1 calls
1>        2 ms  _AddLibraryProjectsEmbeddedResourceToProject   1 calls
1>        3 ms  _ComputeAndroidAssetsPaths                 1 calls
1>        3 ms  CopyFilesToOutputDirectory                 1 calls
1>        3 ms  CoreClean                                  1 calls
1>        3 ms  _CollectPdbFiles                           1 calls
1>        3 ms  GetBuiltProjectOutputRecursive             1 calls
1>        3 ms  _CollectConfigFiles                        1 calls
1>        3 ms  _ValidateAndroidPackageProperties          1 calls
1>        3 ms  _WriteResolvedAssemblies                   1 calls
1>        4 ms  _CreatePropertiesCache                     1 calls
1>        4 ms  _ResolveMonoAndroidSdks                    1 calls
1>        4 ms  _AddDebugStaticResources                   1 calls
1>        4 ms  _BuildLibraryImportsCache                  1 calls
1>        4 ms  _CollectMdbFiles                           1 calls
1>        5 ms  _CheckForInvalidConfigurationAndPlatform   1 calls
1>        7 ms  _ResolveSatellitePaths                     1 calls
1>        7 ms  _GeneratePackageManagerJava                1 calls
1>        8 ms  _DetermineJavaLibrariesToCompile           1 calls
1>        9 ms  IncrementalClean                           1 calls
1>       10 ms  _AddStaticResources                        1 calls
1>       11 ms  _CleanMonoAndroidIntermediateDir           1 calls
1>       11 ms  _GenerateAndroidResourceDir                1 calls
1>       12 ms  _CleanMsymArchive                          1 calls
1>       18 ms  _SetLatestTargetFrameworkVersion           1 calls
1>       20 ms  ResolveAssemblyReferences                  1 calls
1>       27 ms  ImplicitlyExpandDesignTimeFacades          1 calls
1>       30 ms  _BuildSdkCache                             1 calls
1>       35 ms  _ConvertPdbFiles                           1 calls
1>       45 ms  _CheckTargetFrameworks                     1 calls
1>       46 ms  _ResolveLibraryProjectImports              1 calls
1>       52 ms  _CreateBaseApk                             1 calls
1>       66 ms  _BuildAdditionalResourcesCache             1 calls
1>       72 ms  _CopyMdbFiles                              1 calls
1>       78 ms  _ResolveAssemblies                         1 calls
1>      115 ms  _UpdateAndroidResgen                       1 calls
1>      167 ms  _GenerateJavaStubs                         1 calls
1>      189 ms  _GetPrimaryCpuAbi                          1 calls
1>      453 ms  _CopyIntermediateAssemblies                1 calls
1>      515 ms  _LinkAssembliesNoShrink                    1 calls
1>      657 ms  _CompileToDalvikWithDx                     1 calls
1>      664 ms  _CompileJava                               1 calls
1>      677 ms  CoreCompile                                1 calls
1>
1>Task Performance Summary:
1>        0 ms  CallTarget                                 1 calls
1>        0 ms  MSBuild                                    1 calls
1>        0 ms  ResolveCodeAnalysisRuleSet                 1 calls
1>        0 ms  ReadLinesFromFile                          2 calls
1>        0 ms  GetFrameworkPath                           1 calls
1>        0 ms  FindAppConfigFile                          1 calls
1>        0 ms  AssignCulture                              1 calls
1>        1 ms  GetAppSettingsDirectory                    1 calls
1>        1 ms  ConvertToAbsolutePath                      1 calls
1>        1 ms  RemoveDuplicates                           3 calls
1>        1 ms  AssignTargetPath                           6 calls
1>        1 ms  CollectLibraryAssets                       1 calls
1>        1 ms  AssignProjectConfiguration                 1 calls
1>        1 ms  GetMonoPlatformJar                         1 calls
1>        1 ms  CalculateAdditionalResourceCacheDirectories   1 calls
1>        1 ms  CreateTemporaryDirectory                   2 calls
1>        1 ms  GetAndroidDefineConstants                  1 calls
1>        1 ms  GetAddOnPlatformLibraries                  1 calls
1>        1 ms  ReadImportedLibrariesCache                 1 calls
1>        1 ms  ReadAdditionalResourcesFromAssemblyCache   1 calls
1>        1 ms  CheckProjectItems                          1 calls
1>        1 ms  GetReferenceAssemblyPaths                  2 calls
1>        1 ms  AdjustJavacVersionArguments                1 calls
1>        2 ms  FindUnderPath                              7 calls
1>        2 ms  Message                                   17 calls
1>        2 ms  ReadLibraryProjectImportsCache             1 calls
1>        2 ms  MakeDir                                    6 calls
1>        2 ms  CreateAndroidResourceStamp                 1 calls
1>        2 ms  CreateProperty                            42 calls
1>        2 ms  CopyIfChanged                              1 calls
1>        2 ms  GetAndroidPackageName                      2 calls
1>        2 ms  GetJavaPlatformJar                         1 calls
1>        2 ms  GetExtraPackages                           2 calls
1>        2 ms  CheckDuplicateJavaLibraries                1 calls
1>        2 ms  CreateManagedLibraryResourceArchive        1 calls
1>        3 ms  RemoveUnknownFiles                         1 calls
1>        3 ms  AndroidComputeResPaths                     2 calls
1>        3 ms  CreateResgenManifest                       1 calls
1>        4 ms  GetImportedLibraries                       1 calls
1>        4 ms  GetFilesThatExist                          3 calls
1>        6 ms  Touch                                      7 calls
1>        6 ms  CopyGeneratedJavaResourceClasses           2 calls
1>        7 ms  CreateItem                                20 calls
1>        7 ms  GeneratePackageManagerJava                 1 calls
1>        7 ms  DetermineJavaLibrariesToCompile            1 calls
1>        8 ms  Delete                                    28 calls
1>       10 ms  CopyResource                               4 calls
1>       11 ms  RemoveDirFixed                             5 calls
1>       12 ms  WriteLinesToFile                           5 calls
1>       17 ms  ReadResolvedSdksCache                      1 calls
1>       27 ms  ResolveAssemblyReference                   2 calls
1>       29 ms  GenerateResourceDesigner                   1 calls
1>       29 ms  ResolveSdks                                1 calls
1>       29 ms  ConvertResourcesCases                      3 calls
1>       35 ms  ConvertDebuggingFiles                      1 calls
1>       45 ms  CheckTargetFrameworks                      1 calls
1>       45 ms  ResolveLibraryProjectImports               1 calls
1>       52 ms  CopyMdbFiles                               1 calls
1>       65 ms  GetAdditionalResourcesFromAssemblies       1 calls
1>       77 ms  ResolveAssemblies                          1 calls
1>       92 ms  Aapt                                       2 calls
1>      161 ms  GenerateJavaStubs                          1 calls
1>      186 ms  GetPrimaryCpuAbi                           1 calls
1>      479 ms  Copy                                       7 calls
1>      513 ms  LinkAssemblies                             1 calls
1>      655 ms  CompileToDalvik                            1 calls
1>      660 ms  Csc                                        1 calls
1>      664 ms  Javac                                      1 calls
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:04.08

Notice that we can tell how long this build took: 4 seconds. However that doesn't answer your case, but with a proper log like this, we can then investigate that Target or Task and figure out what your project is bottlenecking on. My guess would be aapt, but that's just because even Android Studio would hang here as this tooling is inside the Android SDK and it responsible for packaging android assets.

EDIT:

It looks like this build took ~2 minutes to build the 2 projects. One being in C:\Development\Apps\trunk\App.Droid\App.Droid.ServiceClient\App.Droid.ServiceClient.csproj and the other in C:\Development\Apps\trunk\App.Droid\App.Droid\App.Droid.csproj (40 / 87 seconds respectively). This seems quite normal for a project with this many third party dependencies to Android Support / Google Play. You can search the string Task "GetAdditionalResourcesFromAssemblies to show 6 places where this is defined. There are 2 Tasks being invoked here due to the 2 Android projects.

It might be worth a comparison of an Android Studio project with that many external dependencies and compare the time. I do know that we currently have quite a bit of on-going work with regards to the GetAdditionalResourcesFromAssemblies Task. However this work won't be available until Cycle 9-10. This work is currently apart of a pull request:

https://github.com/xamarin/xamarin-android/pull/296

(You can tell it's almost brand new due to the commit time).

As you can tell from this Task, there will be the following improvements:

The current Task always downloads data from google. This is regardless of whether the files exist in the Android sdk directory already. This commit changes the GetAdditionalResourcesFromAssemblies task to look in the "extras" folder in the android sdk for the required .aar file. This will mean if a user has an up to date sdk, there will be almost no need to download the files from the internet.

There's also a PR - https://github.com/xamarin/xamarin-android/pull/292 (Thanks @Mikhail)

Which addresses reusing the computed hash which can also lower build times.

TLDR; GetAdditionalResourcesFromAssemblies needs a bit more work for build times to be shorter. This is currently in the works.

EDIT 2:

This is currently resolved in support libraries that include a dependency to https://www.nuget.org/packages/Xamarin.Build.Download/

Jon Douglas
  • 13,006
  • 4
  • 38
  • 51
  • Thanks for your help! Appreciate it. I updated my question with what I did myself to get to the bottom of this issue. Also included the diagnostic build log, as you requested. Hope it helps finding the issue. Thanks again! – avb Nov 15 '16 at 19:10
  • It does have a lot of dependencies indeed. It's a pretty big app. I understand that every dependency takes up x amount of build time, but I asked the question because I found the major increase in build time very odd. One thing I do remember, is that Support library v4 has been split into 5 different packages. This happened in version 24.2.0, so that added some dependencies since I updated from 23.4.0.1. See https://developer.android.com/topic/libraries/support-library/revisions.html#24-2-0-v4-refactor. Could this be the issue? I'm glad to hear you are working on build time improvements. – avb Nov 15 '16 at 21:07
  • 2
    It could be partially the issue. I would have to see a build output log of you running the same Xamarin version but different support library versions(23 vs 24). The reason why these items are "split" off is because Google did this in the recent version. You can see this on the revision history: https://developer.android.com/topic/libraries/support-library/revisions.html#24-2-0-v4-refactor (Manually check 24.2.0 as the link doesn't work) I do believe that this fix in this Task would resolve most of the problem in your build time though. – Jon Douglas Nov 15 '16 at 21:21
  • Ok, I'll see if I can get that build log. The solution currently has 5 projects. 1 main app project, 3 Android class libraries and 1 other class library which is shared with another app. Maybe build time decreases if I merge the three unshared projects into the main Xamarin Android project? I'll try that as well. Hope that Task fix solves the problem. – avb Nov 15 '16 at 21:36
  • 1
    I think the only big difference we will see will be the less build time for v23 vs. v24 due to the separation of packages and the `Task` always downloading data. Thus there won't be a great way to work around this until that is fixed. – Jon Douglas Nov 15 '16 at 21:59
  • 1
    Just updated the question with a build log for v23. It's a significant difference in build time. Could you please check it out and see if you find anything? Thanks for your support! – avb Nov 17 '16 at 12:36