-
Notifications
You must be signed in to change notification settings - Fork 564
Description
Description
When both an Android application and a library project include Android Resources, the Application's Resource.UpdateIdValues() is called to update all of the library project's static resource id's with the constant resource id's from the application.
This function is triggered by a call to Android.Runtime.ResourceIdManager.UpdateIdValues() in the static constructor of Resource.Designer.cs, and also by all of it's child classes eg. Drawable, Layout, etc.
The ResourceIdManager.UpdateIdValues() function has an "id_initialized" flag that's supposed to prevent the function getting called twice, however this flag isn't set until after UpdateIdValues() is complete.
https://github.com/xamarin/xamarin-android/blob/52417bdb6bf156a11a391abfc25f84cd5e18cec2/src/Mono.Android/Android.Runtime/ResourceIdManager.cs#L30
Because all of the child classes (Drawable, Layout, etc.) also call UpdateIdValues() in their static constructors, this function is triggered again each time the original call accesses one of the static child classes to update its resource id's, recursively triggering this function call again.
For example, in my Xamarin.Forms w/GooglePlay project I count this function being called 36 times during startup, for a total duration of 23 seconds, where as one call would have only taken 2 seconds.
A simple fix would be to set id_initialized to true immediately the first time the function is called, before the rest of the function is processed.
Steps to Reproduce
- Create a solution that includes both an Android Application and a Library project.
- Include Resources in both projects (or reference a NuGet package that includes Android Resources).
- When debugging, put a break point on the UpdateIdValues() function in the the Application's Resource.Designer.cs file. Observe that it is called multiple times, once for each of the static children classes.
Expected Behavior
The UpdateIdValues() function in the the Application's Resource.Designer.cs file should only be called once.
Actual Behavior
The UpdateIdValues() function is unnecessarily called multiple times, adding ~23 seconds to the application startup time in the case of my project.
Basic Information
Microsoft Visual Studio Enterprise 2017
Version 15.6.5
VisualStudio.15.Release/15.6.5+27428.2027
Microsoft .NET Framework
Version 4.7.02556
Xamarin.Android SDK 8.2.0.16 (HEAD/a78295902)
Xamarin.Android Reference Assemblies and MSBuild support.