how to reference an asset in a library project

This is now possible using the Gradle build system.

Testing with Android Studio 0.5.0 and v0.9 of the Android Gradle plugin, I've found that files such as

MyLibProject/src/main/assets/test.html

are correctly packaged in the final application and can be accessed at runtime via the expected URL:

file:///android_asset/test.html

This answer is out of date, the gradle build system and AAR files support assets.


From the Android Docs:

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.

If you want to include files from a Library project, you'll need to put it in the resources instead of the assets. If you're trying to load HTML files from your library project into a WebView, this means that you'll have to go a more roundabout method than the usual asset URL. Instead you'll have to read the resource data and use something like loadData.


You can achieve this by creating a symbolic link in the project's asset folder that points to the directory in the library project.

Then you can access as below:

webview.loadUrl("file:///android_asset/folder_in_a_libary_project/info.html", null);