Android Crazy Long Build Times - GetAdditionalResourcesFromAssemblies

When compiling with the latest XS (full version log here) Android is taking a LOOOONG time. From the output, it seems like the culprit is:

150566 ms  _BuildAdditionalResourcesCache             1 calls
150564 ms  GetAdditionalResourcesFromAssemblies       1 calls

Those two lines look to be the same thing, but are from the Task Performance Summary and Target Performance Summary: respectively.

So, the question is. What are those doing, and how can I speed that up?

Full build log here

Posts

  • caracarncaracarn USMember

    As another note on this. This seemed to become much longer when updating the various google support libs from v23 to v24.

  • MikhailMelnikMikhailMelnik AUMember ✭✭

    Same thing.

    Sample project with referenced AppCompat and enabled multidex has a 1.5 minute build time which is ridiculous:

    Task Performance Summary:
        ...
         4546 ms  CreateMultiDexMainDexClassList             1 calls
         4691 ms  Aapt                                      10 calls
        12938 ms  CompileToDalvik                            1 calls
        52599 ms  GetAdditionalResourcesFromAssemblies       1 calls
    
    Build succeeded.
    
    CREATEMULTIDEXMAINDEXCLASSLIST : warning : can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [android-support-multidex.jar:META-INF/MANIFEST.MF])
    CREATEMULTIDEXMAINDEXCLASSLIST : warning : can't write resource [.readme] (Duplicate zip entry [classes.jar:.readme])
        2 Warning(s)
        0 Error(s)
    
    Time Elapsed 00:01:24.06
    

    Moreover even this small example generates build warnings from multidex.

  • Same here...

    867 ms  LinkAssemblies                             1 calls
    910 ms  RemoveDirFixed                             9 calls
    2093 ms  GenerateJavaStubs                          1 calls
    2673 ms  CreateAdditionalLibraryResourceCache       1 calls
    4748 ms  Javac                                      1 calls
    7881 ms  Aapt                                      14 calls
    8887 ms  CompileToDalvik                            1 calls
    **52924 ms  GetAdditionalResourcesFromAssemblies       1 calls**
    Build succeeded.
    Time Elapsed 00:01:25.23
    ========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========
    
  • MikhailMelnikMikhailMelnik AUMember ✭✭

    Looks like the possible root cause was fixed three days ago here: https://github.com/xamarin/xamarin-android/pull/292.

    In the comments the commit author demonstrated build time decreased from 7 to 2 minutes.

    Xamarin Team, please include this fix (if it is a fix) to stable as soon as possible!

  • Xamarin Team, please include this fix (if it is a fix) to stable as soon as possible!

    +

  • MikhailMelnikMikhailMelnik AUMember ✭✭

    I have managed to make a temporary workaround based on commit I've mentioned above.

    As we normally do not add new packages between builds zip verification can be skipped so I have altered a method Xamarin.Android.Tasks.GetAdditionalResourcesFromAssemblies.IsValidDownload from C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Build.Tasks.dll assembly from Xamarin distribution to always return true on validation call which decreased original 1.5 minutes to 20 seconds.

    Well, I still have issues with other tasks which makes build longer but at least it was a good speed up.

  • @MikhailMelnik said:
    As we normally do not add new packages between builds zip verification can be skipped so I have altered a method Xamarin.Android.Tasks.GetAdditionalResourcesFromAssemblies.IsValidDownload from C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Build.Tasks.dll

    Could you please explain how did you "altered" that method? Did you have to recompile xamarin sources?

  • MikhailMelnikMikhailMelnik AUMember ✭✭

    @PatrykStrzelecki yep, I've used ILSpy + Reflexit to alter method's body to always return true.

  • PatrykStrzeleckiPatrykStrzelecki USMember
    edited November 2016

    before:

    867 ms LinkAssemblies 1 calls
    910 ms RemoveDirFixed 9 calls
    2093 ms GenerateJavaStubs 1 calls
    2673 ms CreateAdditionalLibraryResourceCache 1 calls
    4748 ms Javac 1 calls
    7881 ms Aapt 14 calls
    8887 ms CompileToDalvik 1 calls
    52924 ms GetAdditionalResourcesFromAssemblies 1 calls
    Build succeeded.
    Time Elapsed 00:01:25.23

    after:

    79 ms GetAdditionalResourcesFromAssemblies 1 calls
    (...)
    1565 ms GenerateJavaStubs 1 calls
    3664 ms Javac 1 calls
    6605 ms CompileToDalvik 1 calls
    9329 ms Aapt 14 calls
    Build succeeded.
    Time Elapsed 00:00:27.48

    I can confirm that now compile time has been reduced from 1:25 to 0:27 min.

  • I've tried your sugestions, and...

    before fix:

    867 ms LinkAssemblies 1 calls
    910 ms RemoveDirFixed 9 calls
    2093 ms GenerateJavaStubs 1 calls
    2673 ms CreateAdditionalLibraryResourceCache 1 calls
    4748 ms Javac 1 calls
    7881 ms Aapt 14 calls
    8887 ms CompileToDalvik 1 calls
    52924 ms GetAdditionalResourcesFromAssemblies 1 calls
    Build succeeded.
    Time Elapsed 00:01:25.23

    after fix:

    699 ms ConvertResourcesCases 3 calls
    712 ms Copy 9 calls
    770 ms RemoveDirFixed 9 calls
    1161 ms CreateAdditionalLibraryResourceCache 1 calls
    1842 ms GenerateJavaStubs 1 calls
    3671 ms Javac 1 calls
    6736 ms CompileToDalvik 1 calls
    9281 ms Aapt 14 calls
    Build succeeded.
    Time Elapsed 00:00:27.55

  • DeanEllisDeanEllis USXamarin Team Xamurai

    I am investigating the issue with the latest v24 support library.. its strange that it has such a massive effect on the build times.
    In the mean time we have just introduced https://github.com/xamarin/xamarin-android/pull/296 . This will look for the required .aar files in the AndroidSdk directory BEFORE trying to download.

    To make use of this (in a future release) you need to make sure your Android Sdk Manager is up to date and that you have the latest "Android Support Repository" installed. Same applies for the Google Play items in the Sdk Manager (if you use Google play services).

  • DeanEllisDeanEllis USXamarin Team Xamurai

    We will try to get the changes we make into the earliest release we can, as we know what a pain point this is for you all.

  • before:

    867 ms LinkAssemblies 1 calls
    910 ms RemoveDirFixed 9 calls
    2093 ms GenerateJavaStubs 1 calls
    2673 ms CreateAdditionalLibraryResourceCache 1 calls
    4748 ms Javac 1 calls
    7881 ms Aapt 14 calls
    8887 ms CompileToDalvik 1 calls
    52924 ms GetAdditionalResourcesFromAssemblies 1 calls
    Build succeeded.
    Time Elapsed 00:01:25.23

    after:

    699 ms ConvertResourcesCases 3 calls
    712 ms Copy 9 calls
    770 ms RemoveDirFixed 9 calls
    1161 ms CreateAdditionalLibraryResourceCache 1 calls
    1842 ms GenerateJavaStubs 1 calls
    3671 ms Javac 1 calls
    6736 ms CompileToDalvik 1 calls
    9281 ms Aapt 14 calls
    Build succeeded.
    Time Elapsed 00:00:27.55

Sign In or Register to comment.