Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 653
Macarse Avatar asked May 04 '11 21:05

Macarse


People also ask

How do I retrieve files from assets folder?

Right click on the assets folder, select New >> file (myText. txt) and your text. “Darkness cannot drive out darkness: only light can do that. Hate cannot drive out hate: only love can do that.”

Where are Android assets stored?

I noticed that , when an android app is installed, It's apk file is copied to "data/app" directory. If I open it from there - just selecting view, I see assets folder which contains my files. That is correct. The APK is copied there during installation, but the asset files are left inside it.


4 Answers

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/)
like image 121
thaussma Avatar answered Oct 03 '22 06:10

thaussma


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

like image 43
igork Avatar answered Oct 03 '22 08:10

igork


From Eclipse and ANT you can reference the same "assets" folder from multiple projects. This allows your source tree to have a single copy of the assets files, but have them included in multiple APKs.

See Android: targeted res folders for debugging in eclipse

From ProjectA I was able to reference ..\ProjectA\Assets from ProjectB. On Eclipse (under Windows at least, I've not tried on Linux yet), I had to create a new variable to reference ..\ProjectA and use that variable in "Linked Folder Location". If I attempted to use ".." in "Linked Folder Location" eclipse wouldn't accept it.

like image 31
joeking Avatar answered Oct 03 '22 07:10

joeking


For those using IntelliJ IDEA, you can make a change to your application module's packaging settings to include depedent assets. Note, this was done on version 14.0.2 of IntelliJ Community edition. My main application module now inherits files form my library project's assets folder as if they were right in the main project!

Right click application module > Open Module SEttings. Select Android tree node on module > Packaging Tab. Check "Include assets from dependencies into APK"

Note: I've never used Android Studio, but I would guess there is a similar setting for this in that application.

enter image description here

enter image description here

like image 30
Stealth Rabbi Avatar answered Oct 03 '22 08:10

Stealth Rabbi