Ajas
Ajas

Reputation: 141

Error with build.xml for unrecognized directories in res/

I am trying to port an existing C++ app to android using JNI. However, after generating the Build.xml file from the AndroidManifest.xml and attempting to build with it, I get the following (relevant) output:

[aapt] Generating resource IDs...
     [aapt] invalid resource directory name: /{Project Directory}/res/audio
     [aapt] invalid resource directory name: /{Project Directory}/res/img

BUILD FAILED
/{Android SDK Dir}/tools/ant/build.xml:560: The following error occurred while executing this line:
/{Android SDK Dir}/tools/ant/build.xml:589: null returned: 1

These are existing directories in a directory already named "res" by coincidence, not meant to have a semantic meaning for Java. If I remove those from res/ then it builds just fine. So my question is-- what is the best way to organize this (or tell ant to ignore unrecognized directories)? Res is already a very large directory structure with mainly .png .mp3 and text files.

Upvotes: 1

Views: 4579

Answers (2)

dskinner
dskinner

Reputation: 10857

If renaming them is out of the question for whatever reason, you could override -package-resources in the build.xml and customize aapt, specifying a new location for res/ along with various other options to handle issues that might come up (Then aapt would be the part to research).

You can inspect android-sdk/tools/ant/build.xml for what that target already does, but essentially you would simply paste in the following to your own build.xml

<target name="-package-resources">
    <echo>Packaging resources</echo>
    <aapt executable="${aapt}"
        command="package"
        verbose="${verbose}"
        versioncode="${version.code}"
        manifest="AndroidManifest.xml"
        assets="${asset.absolute.dir}"
        androidjar="${android.jar}"
        apkfolder="${out.absolute.dir}"
        resourcefilename="${resource.package.file.name}"
        projectLibrariesResName="${project.libraries.res}"
        projectLibrariesPackageName="${project.libraries.package}"
        resourcefilter="${aapt.resource.filter}">

        <res path="${resource.absolute.dir}"/>
    </aapt>
</target>

and customize to your needs.

Also notice that it pulls the res path from resource.absolute.dir, so if thats all you really need to do, then you could set that in ant.properties or whatever the default properties file is in the sdk tools are that you're using. Just inspect the build.xml to see or add a new loadproperties line pointing to your own. IIRC, resource.absolute.dir gets set based on resource.dir, so you might have to try each but in the properties file you would just set

resource.dir=new/path/to/res

Upvotes: 1

Reed
Reed

Reputation: 14984

audio goes in {Project Directory}/res/raw and images go in {Project Directory}/res/drawable

This page may be of some use to you:
http://developer.android.com/guide/topics/resources/index.html

Upvotes: 0

Related Questions