34

I have an Android Library Project that contains several styles/themes defined in its styles.xml file.

Normally, when referencing this style in some other xml layout or manifest file, you would just write android:theme="@style/TheNameOfTheStyle"

When using a library project, how does the dependent project properly reference that style now? Just leaving it as android:theme="@style/TheNameOfTheStyle" gives me an error saying there is no resource found matching that name.

I guess this same question applies for other references like @string, @color etc.

Thanks

Edit: Ok so it appears that you are suppose to reference it just like normal, but the console in eclipse is giving me this error:

Error: No resource found that matches the given name (at 'theme' with value '@style/ThemeName').

(facepalm) Edit

I just needed to "Clean Project" in Eclipse. Now it's working.

cottonBallPaws
  • 21,220
  • 37
  • 123
  • 171
  • In an android book I am reading it says you can/should refer to the other resource as @[packagename.]type/id where package name if left out if the current app package, and you can use the page name of your library project. BUT, it doesn't work for me, neither does cleaning the project and rebuilding :-( – Andrew Mackenzie Oct 08 '12 at 09:08
  • @Andrew You don't need to put in the package name like that. If the resource is in your library project, you can just reference it normally as if it was in your own project. – cottonBallPaws Oct 08 '12 at 18:52
  • Note: First link is deprecated. – user905686 Sep 14 '16 at 09:56

4 Answers4

16

Its important to build the project after adding resources (or just have autobuild on) and cleaning the project helps most of the times. Restarting Eclipse when "something" go wrong is a good idea, too.

Also note that Android merges the recources, so the last project that is build "wins" the name. For this reason it's a good idea to prefix ALL resources somehow.

Rafael T
  • 15,401
  • 15
  • 83
  • 144
  • 1
    While your solution didn't solve my specific problem (see my edit in the question for how my problem was resolved), it seems your answer has helped others who have found their way to this question. So I will mark your answer as accepted. – cottonBallPaws May 21 '12 at 18:18
3

I use IntelliJ and what worked for me is to reference the resource normally and to make sure the library is added as a dependency of the project

AlanKley
  • 4,592
  • 8
  • 40
  • 53
2

I just ran into the same issue however cleaning in Eclipse did not work until I set both the library project and the regular project to have a matching : Target Build Property.

nicordesigns
  • 904
  • 1
  • 9
  • 18
0

I just had this issue in Android Studio. It seems Android Studio didn't realise my library project was a library despite the project.properties stating android.library=true.

I fixed this issue by checking the "Is Library" checkbox in Project Structure.

enter image description here

bencallis
  • 3,478
  • 4
  • 32
  • 58