Bug 9493 - Android Class Library doesn't generate Resource.Designer.cs
Summary: Android Class Library doesn't generate Resource.Designer.cs
Status: RESOLVED DUPLICATE of bug 5870
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.4.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2013-01-11 10:10 UTC by Mihai
Modified: 2013-02-05 15:43 UTC (History)
4 users (show)

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

Android library project test (182.05 KB, application/octet-stream)
2013-01-15 03:53 UTC, Mihai

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:

Description Mihai 2013-01-11 10:10:08 UTC

I've created an Android Class Library project, added one Activity and one "png" in Resources/Drawable and when I build the Resource.Designer.cs file isn't created.
In the build output I see:


So Monodroid is aware of the "png" file but for some reason doesn't create the Resource.Designer.cs file.

I'm using 
- Monodroid 4.4.54
- Visual Studio 2010 Ultimate Version 10.0.40219.1 SP1 

Comment 1 Mihai 2013-01-11 10:13:03 UTC
Created attachment 3199 [details]
Example project that I've tried
Comment 3 Jonathan Pryor 2013-01-11 13:15:54 UTC
Unfortunately the current Class Library templates don't make it possible to use Android Resource.

Currently, the easiest way to create an Android Class Library project which contains resources is to instead create an Android Application project, then hand-edit the .csproj to remove the following element:


You will now have a Class Library project which will build Android resource.

If you have an existing Android Library project, you can add support for Android resources by adding an <AndroidResgenFile/> element, and adding a <Compile/> for the $(AndroidResgenFile) value, e.g. the patch to Attachment #3199 [details]:

--- AndroidClassLibraryTest.csproj.bk	2013-01-11 13:11:37.000000000 -0500
+++ AndroidClassLibraryTest.csproj	2013-01-11 13:11:53.000000000 -0500
@@ -10,6 +10,7 @@
+    <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
@@ -42,6 +43,7 @@
     <Compile Include="Class1.cs" />
+    <Compile Include="Resources\Resource.designer.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />

With these two changes, Android Class Library projects will build Android Resources.
Comment 4 Mihai 2013-01-14 05:56:03 UTC
I've tried the first solution and it worked.
I have another question: I have 2 apps which share 70% of the code and most of the views are basically the same except for some design differences. Is there a way of using the "base" app as a library project for the other one ?
As in: re-use the common code and just override differences in code and design.
This would really help me out because until now I've just duplicated the code and I'm planning on a major update and I would want to have to copy-paste everything from on app to another

Thank you,
Comment 5 Mikayla Hutchinson [MSFT] 2013-01-14 14:09:42 UTC
I would recommend that you use links, i.e. add the files from one project to the other, but as links instead of copies.
Comment 6 Mihai 2013-01-15 03:11:26 UTC
I've tried replying to support@xamarin.com but the mail couldn't be delivered. This is what I wrote in that email

I'm not sure what you mean by "view objects". 

What I've tried so far is to use Jonathan Pryor's first suggestion https://bugzilla.xamarin.com/show_bug.cgi?id=9493#c3 (I've removed  <AndroidApplication>True</AndroidApplication> from an Android Application Project) but I am having some problems: I've added the project AndroidLibraryTest2 as a reference to SampleApplication project, I've added a new Layout in the SampleApplication project, but when I try to open it I get this error:

"The operation could not be completed. Invalid pointer"

Perhaps I'm missing something on how reusing an application is suppose to work.
Comment 7 Mihai 2013-01-15 03:53:08 UTC
Created attachment 3218 [details]
Android library project test
Comment 8 Mihai 2013-01-15 03:53:28 UTC
The second attached project is what I've tried
Comment 9 Jonathan Pryor 2013-01-16 22:00:20 UTC
@Mihai: Unfortunately I don't understand Comment #6.

> I'm not sure what you mean by "view objects". 

I'm not sure which message you're referring to, so I don't know what is meant by "view objects" either. I imagine a "View object" is an instance of an Android.Views.View subclass.

>  I am having some problems: I've added the project AndroidLibraryTest2
>  as a reference to SampleApplication project, I've added a new Layout in 
> the SampleApplication project, but when I try to open it I get this error:
>   "The operation could not be completed. Invalid pointer"

This further confuses me:

1. Attachment 3218 [details] has two projects, AndroidLibraryTest2 and SampleApplication. However, SampleApplication doesn't have AndroidLibraryTest2 as a Project Reference, thus apparently contradicting the above. Furthermore, both projects aren't in the same solution (.sln), so they can't reference each other anyway.

2. What's the name of the New Layout?

3. What _exactly_ did you do to get the "Invalid pointer" message? Is that coming from MonoDevelop? From the build/ From running on the target device?

 - Jon
Comment 10 Sebastian Krysmanski 2013-02-05 12:33:49 UTC
May I ask why this issue was marked as "INVALID"? It's still an open issue.
Comment 11 Jonathan Pryor 2013-02-05 15:43:11 UTC
@Sebastian: Then let's call it a dupe of Bug #5870. :-)

*** This bug has been marked as a duplicate of bug 5870 ***