How to reference an icon from a Library Project in Application's AndroidManifest.xml
Asked Answered
D

2

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?

Duumvir answered 13/6, 2011 at 18:41 Comment(7)
Did you try with drawable/icon only ? I don't know about your setup but it works for me.Puerility
@Puerility @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?Duumvir
@Puerility 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. :)Duumvir
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...Gog
@Gog For other drawables see the link I mentioned when I first posted my question: #6241929 The keyword appears to be layout XML.Duumvir
Thanks for the response, @Duumvir . I'm still not able to get that to work though...wondering if it might be the way I have the project structured.Gog
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: developer.android.com/guide/developing/projects/…Stiver
P
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...

Puerility answered 13/6, 2011 at 19:14 Comment(1)
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...Duumvir
D
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.

Dippold answered 4/10, 2012 at 11:13 Comment(2)
For future reference, This is more of a comment than an answer. :)Casaba
Don't agree. If you see the mess in the comment section below the OP's question i think it deserves to be an answer. :)Conciliate

© 2022 - 2024 — McMap. All rights reserved.