Slow app build - Xamarin for Visual Studio

后端 未结 1 1364
无人及你
无人及你 2021-01-31 19:12

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
相关标签:
1条回答
  • 2021-01-31 19:52

    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/

    0 讨论(0)
提交回复
热议问题