Bug 39185 - Resource file in Android library defines resources as static int rather than const int
Summary: Resource file in Android library defines resources as static int rather than ...
Status: RESOLVED FEATURE
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 7.1 (C9)
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2016-02-28 09:24 UTC by Andy
Modified: 2017-01-03 14:01 UTC (History)
7 users (show)

Tags: BZCU
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description Andy 2016-02-28 09:24:54 UTC
Hi,

I've moved a lot of my UI into an Android Library project so I can share it between applications.  In doing so, I have noticed that the Resource IDs declared in Resource.Designer.cs are now declared as public static int rather than public const int as in an Android Application project.

This causes a number of issues but in particular I have an Attribute class that takes a Resource ID such as:

[Attribute(int id)]

This no longer works as you can't use a static variable in an attribute, only a constant.

Is this expected behaviour as it doesn't make sense to me why there would be a difference between an Android Library project and an Android Application project?
Comment 1 Juan Marcelo Tondato 2016-12-29 17:52:42 UTC
Moving the bug to Android for visibility from the right team.
Thanks for reporting!
Comment 2 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.