Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Share resources between different projects

Hi all I have a problem like this: I have a project that defines a class for error handling that I draw from other projects. I noticed that if I do not copy the contents of the file "string" of the project class in the file "strings" of the project in which I refer to the class the application crashes. Is there a way to avoid copying the resources thus avoiding to do this every time I change something in the class referenced?
thanks Sergio

sdk 10


  • JonathanPryorJonathanPryor USXamarin Team Xamurai

    I noticed that if I do not copy the contents of the file "string" of the project class in the file "strings" of the project in which I refer to the class the application crashes.

    I do not understand what you mean here. Xamarin.Android does not support the Content Build action, so how are you/are you not "copy[ing] the contents of the file string'"? Is it an Android resource? Something else?

  • SergioMatteoniSergioMatteoni ITMember

    Yes it is an android resources ex: Values / Strings

  • JonathanPryorJonathanPryor USXamarin Team Xamurai

    Library projects support Android Resources (and have since 4.4), though it's not particularly easy at this time to do so:

    1. Create a new Android Application project.
    2. Close the solution.
    3. Edit the .csproj
    4. Remove all <AndroidApplication>True</AndroidApplication> elements (case insensitive).

    (4) turns an Application project into a Library project, with the added benefit that you now have the Resources directory already created. ;-)

    The resources referenced by an Library project are embedded into the Library assembly, and are extracted and merged with the app's resources when creating the .apk.

  • kspangkspang MYMember ✭✭

    In latest Xamarin Studio and Xamarin.Android, we need NOT to edit the .csproj file manually.
    Simply adding a "Android Library Project" will provide the required "resources" directory.

    For TS's question, it sounds like the Resource.Designer.cs is not synchronized across the solution or the resources Ids are not updated.

    For former case, you may remove all the Resource.Designer.cs physical files to force re-generation (workaround).

    For later case, you may need to call "ResourceIdManager.UpdateIdValues();" in the constructor as stated here. (workaround)

  • BradRobinsonBradRobinson AUMember ✭✭✭

    @jonp are you sure that android library project strings actually work? In my experience it's fairly broken:

    If it's not broken, I'd love to know what I'm doing wrong.

  • SergioMatteoniSergioMatteoni ITMember

    Thanks Jonp and Kspang. I have added the code suggested from Eno at this link then I have added a call "ResourceIdManager.UpdateIdValues();" in the constructor and now all work's fine. But in the future, when Mono will be updated, the presence of this workaround in to all my library project should raise any problem ?

  • kspangkspang MYMember ✭✭

    @SergioMatteoni, if you are in doubt, then you may try the v4.7.2 Alpha version.

    Perhaps, such workaround is not needed.

  • So what is the go to solution for the problem of 'sharing resources' across multiple Android projects. I have this little library which has a bit of shared code and resources. However the resources from the library seem to be missing from the final Resource.Designer.cs

Sign In or Register to comment.