7

I am trying to use the same application icon for all applications derived from a Library Project.

I thought that it would be as simple as implementing the advice provided in this thread, but unfortunately it doesn't work.

What I did is add to the <manifest> tag in the application's AndroidManifest.xml the following line:

xmlns:mylib="http://schemas.android.com/apk/res/com.example.baseapp"

And a few lines down the same AndroidManifest.xml file, change the typical @drawable/icon to:

   <application android:icon="@mylib:drawable/icon">

But it doesn't work!

Instead, Eclipse tells me that:

error: Error: No resource found that matches the given name (at 'icon' with value '@omlib:drawable/icon').

Apparently, referencing drawables from a layout XML and the manifest XML are not the same.

How do I reference an icon from a Library Project in Application's AndroidManifest.xml?

Community
  • 1
  • 1
an00b
  • 11,338
  • 13
  • 64
  • 101
  • 2
    Did you try with drawable/icon only ? I don't know about your setup but it works for me. – Snicolas Jun 13 '11 at 18:53
  • @Snicolas `@drawable/icon` works but it requires copying the icon's PNG file to each and every application project that uses my Library Project. That is not what I want. I want to have the icon PNG file exist only once (in the Library Project) and reference it from all other (numerous) applications using it. Suggestion? – an00b Jun 13 '11 at 18:56
  • @Snicolas I am taking what I wrote above back! I just re-tried @drawable/icon but this time **with all icon.png files deleted from application's res subfolders** and it works! Phew... this is so tricky (with no apparent consistency or methodology). Please post your comment as an answer so that I can accept it. +1 in the meanwhile. :) – an00b Jun 13 '11 at 19:07
  • Does this work for other drawables as well, and just not XML resources? I've tried the same with XML resources, but with no luck. It's a pain having to copy and paste identical resources so much each time I make a change... – areyling Jun 13 '11 at 19:14
  • @areyling For other drawables see the link I mentioned when I first posted my question: http://stackoverflow.com/questions/6241429/how-to-reference-a-drawable-from-a-library-project-into-a-main-projects-layout-i/6241484#6241484 The keyword appears to be **layout** XML. – an00b Jun 13 '11 at 19:28
  • Thanks for the response, @an00b . I'm still not able to get that to work though...wondering if it might be the way I have the project structured. – areyling Jun 14 '11 at 15:05
  • For anyone else that struggled with this the way I did, there's a specific way to specify that an Android project is a library. I was trying to follow the help here without having done this; I only had the library listed as a Java dependency. Article here: http://developer.android.com/guide/developing/projects/projects-eclipse.html – atraudes Jul 11 '11 at 16:58

2 Answers2

8

Did you try with drawable/icon only ? I don't know about your setup but it works for me.

Perhaps after a good project and librairy clean up...

Snicolas
  • 37,840
  • 15
  • 114
  • 173
  • 2
    Your tip still holds true... even on the latest SDK R16... But another important tip must be added: When all fails, **exit Eclipse**, then start it again. It's sad to see how a remarkable productivity tool like Eclipse needs to resort to those kind of tricks, formerly attributed to Microsoft's operating systems... – an00b Jan 24 '12 at 23:22
6

For people still reading this: I believe this was fixed since SDK17.

you should write the following:

xmlns:mylib="http://schemas.android.com/apk/res-auto"

This should enable you to reference resources from library projects as well.

Spoetnic
  • 594
  • 7
  • 10