how to access resources in a android library project

Then I wonder where I can put these resources and how to access them?

From Android Doc’s

Library projects cannot include raw assets

The tools do not support the use of raw asset files (saved in the assets/ directory) in a library project. Any asset resources used by an application must be stored in the assets/ directory of the application project itself. However, resource files saved in the res/ directory are supported.

Docs Reference Link : LibraryProjects

Solution : How to access resource files saved in res/ directory of library project from application project

Note : If you want to access the resources from Library Project itself add the resources to res/ directory not in assets. Because the files in assets won’t be bundled with the .jar file.
You can access it as usual using the reference generated in R.java file.

Ex: To access a image from drawable use

R.drawable.image_name

Does it mean that I have to hold a reference of the Context object anywhere I want to get any resources?

Really you should hold a reference to context to access the resources

Update:

Now Android library project can be generated as aar (Android Archive) file which allows you to bundle the resource files needed for the library project instead of the old jar (Java Archive) file which only allow you to bundle Java classes.

Leave a Comment