Android Library assets folder doesn't get copied

I am creating an Android library and it has an assets folder with images. When I use it in another project the assets doesn't get copied.

Anyone else had this issue?


Solution 1:

The new Android Build System that is based on Gradle supports asset folders in library projects!

With ANT based builds it's still not possible:

Library projects cannot include raw assets. (See docs)

But you could

  • copy the assets manually
  • or even patch the aapt tool (see http://devmaze.wordpress.com/2011/06/26/enabling-assets-in-android-libraries/)

Solution 2:

It is possible to put assets into resulting library jar by small fix:
Put "custom_rules.xml" into you library project home (near the build.xml):

<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
    <target name="-post-compile" if="${project.is.library}">
    <echo>Post Compile: add assests from ${asset.absolute.dir} to ${out.library.jar.file}</echo>
    <jar destfile="${out.library.jar.file}" update="true">
        <zipfileset dir="${asset.absolute.dir}" prefix="assets" excludes="**/*.java ${android.package.excludes}"/>
    </jar>
</target>

This will pack your library assets into you resulting library jar. As result, these assets will be included into resulting .apk of your application.

Checked on Android SDK Tools Revision 21.1.0 on OSX