Documentation for aapt element in Ant script
Asked Answered
E

3

9

I'm working on some Ant scripts for an Android build system and have come across an element to call aapt. I have seen lots of examples with

exec executable="${aapt}"

but the ones that come out of the main_rules.xml file use a different format

    <aapt executable="${aapt}"
            command="package"
            debug="${build.packaging.debug}"
            manifest="AndroidManifest.xml"
            assets="${asset.absolute.dir}"
            androidjar="${android.jar}"
            apkfolder="${out.absolute.dir}"
            resourcefilename="${resource.package.file.name}"
            resourcefilter="${aapt.resource.filter}">
        <res path="${resource.absolute.dir}" />
        <!-- <nocompress /> forces no compression on any files in assets or res/raw -->
        <!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets and res/raw -->
    </aapt>

I would like to rename the package using this element, but cannot find any documentation about how to use it. Does anyone know where I can find some?

Thanks

Excitant answered 24/7, 2011 at 20:52 Comment(0)
E
7

I couldn't find anything and ended up using the following which seems to work

    <exec executable="${aapt}" failonerror="true">
      <arg value="package" />
      <arg value="-f" />
      <arg value="-v" />
      <arg value="-M" />
      <arg path="AndroidManifest.xml" />
      <arg value="-A" />
      <arg path="assets" />
      <arg value="-I" />
      <arg path="${android.jar}" />
      <arg value="-m" />
      <arg value="-J" />
      <arg path="${out.absolute.dir}" />
      <arg value="-F" />
      <arg path="${out.absolute.dir}/${resource.package.file.name}" />
      <arg value="-S" />
      <arg path="res" />
      <arg value="--rename-manifest-package" />
      <arg value="my.new.package.name" />
    </exec>
Excitant answered 26/7, 2011 at 8:45 Comment(0)
J
7

In the new(er) version of the Android SDK, the ant build script works in a different way. It does not directly invoke the aapt command via an exec element but rather defines an aapt task. The latter one is implemented by the java class com.android.ant.AaptExecTask. This class only provides a subset of the aapt command line options.

You can find a brief description of the mapping between aapt command line options and the ant parameters below as found in the source java doc:

Aapt Option             Ant Name        Type
---------------------------------------------------------------------------------
path to aapt            executable      attribute (Path)
command                 command         attribute (String)
-v                      verbose         attribute (boolean)
-f                      force           attribute (boolean)
-M AndroidManifest.xml  manifest        attribute (Path)
-I base-package         androidjar      attribute (Path)
-A asset-source-dir     assets          attribute (Path
-S resource-sources     <res path="">   nested element(s)
                                        with attribute (Path)
-0 extension            <nocompress extension="">  nested element(s)
                        <nocompress>               with attribute (String)
-F apk-file             apkfolder                  attribute (Path)  
                        outfolder                  attribute (Path) deprecated
                        apkbasename                attribute (String)
                        basename                   attribute (String) deprecated

-J R-file-dir       rfolder         attribute (Path)
                                    -m always enabled

As far as I found out, there is no way to provide the generic aapt options through this new build task. This seems to be possible only by taking a modified copy of the SDK's build.xml with replacements for the aapt invocations.

If anyone knows a better solution, I'd be glad to read about, too ;-)

EDIT: In even newer versions of the SDK the introduced renaming packages again:

Aapt Option   --rename-manifest-package package-name 
Ant Name      manifestpackage
Type          attribute (String)
Jutland answered 2/2, 2012 at 10:52 Comment(1)
I find the attribute name of --rename-manifest-package option for long time. This is very helpful for me.Fia
R
1

I highly doubt there is any documentation beyond the source code.

Ry answered 24/7, 2011 at 22:31 Comment(1)
... which can be found for example here: netmite.com/android/mydroid/1.5/development/tools/anttasks/src/…Rameau

© 2022 - 2024 — McMap. All rights reserved.