Compiling Resource IDs: static vs const RRS feed

  • Question

  • User15741 posted

    When I compile my executable project, the various resource IDs end up in the Resource.Designer.cs file like this...

    // aapt resource value: 0x7f01004e
    public const int logo = 2130772046;
    // aapt resource value: 0x7f010049
    public const int navigationMode = 2130772041;

    But in my library project they look like this...

    // aapt resource value: 0x7f01000e
    public static int actionBarDivider = 2130771982;
    // aapt resource value: 0x7f01000f
    public static int actionBarItemBackground = 2130771983;

    Notice the difference between static and const.

    This causes me a small problem with switch-case statements (which demand const-ness), but does anyone know why they might be different? It might be nothing to do with library vs. executable of course, that could be a coincidence.

    Friday, June 27, 2014 2:01 PM

All replies

  • User25081 posted

    I have just noticed this same discrepancy.

    Can someone please clarify why this is the case?? Similar problem when it comes to using switch-case, which I find much cleaner for determining which menu item has been selected, for example.

    Tuesday, August 26, 2014 9:04 AM
  • User209 posted

    I've seen that as well. Create a bug repport, there is no reason to it not being const as Resource.Designer.cs is created prior to compiling it into the project. And as you both say, it breaks switches when they are just static ints...

    Tuesday, August 26, 2014 9:18 AM
  • User38983 posted

    Did this ever get fixed?

    Saturday, April 18, 2015 3:21 PM
  • User112 posted

    I see const int fields (latest beta channel). Also note that static ints aren't fixed - you could chnage their values.

    Saturday, April 18, 2015 4:23 PM
  • User66279 posted

    Any news about this problem?

    This still does not seem corrected. Is there a way to change the "static" to "const"? Edit the Resource file directly is not a solution since that file is regenerated each compilation.

    Wednesday, May 6, 2015 8:07 AM
  • User45180 posted

    A fix for this would be good - 12 months later and still broken.

    I'm having to replace switch statements with if/then/else blocks which is pretty silly.

    Tuesday, June 9, 2015 3:21 PM
  • User123 posted


    Tuesday, June 9, 2015 6:29 PM
  • User2756 posted

    Any movement on this one? I had some lovely theming done with switches that broke when I converted my widget to a library.

    Tuesday, March 8, 2016 1:00 PM
  • User338247 posted

    According to the VS team this is by design:

    dean.ellis 2017-01-03 14:01:43 UTC This is by design. When consuming Library resources we need to be able to update the id's in the library designer.cs file with the ones from the app. In the application designer.cs you will see an UpdateIdValues values handles this.

    This is because the id's will more than likely be different in the library compared to when the app is compiled. This is a result of how the google android aapt tool generates the id's.

    Switching to a static means we would be unable to update those values dynamically.

    Saturday, April 7, 2018 11:19 PM