Ant 脚本中 aapt 元素的文档

发布于 2024-11-25 15:48:39 字数 930 浏览 3 评论 0原文

我正在为 Android 构建系统编写一些 Ant 脚本,并且遇到了一个调用 aapt 的元素。我看过很多

execexecutable="${aapt}"

的示例,但来自 main_rules.xml 文件的示例使用不同的格式

    <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'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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧伤还要旧人安 2024-12-02 15:48:39

我找不到任何东西,最终使用了以下似乎有效的方法

    <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>

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>
伪心 2024-12-02 15:48:39

在新版本的 Android SDK 中,ant 构建脚本以不同的方式工作。
它不会通过 exec 元素直接调用 aapt 命令,而是定义
一项适当的任务。
后一个是由java类com.android.ant.AaptExecTask实现的。
此类仅提供 aapt 命令行选项的子集。

您可以在下面的源 java 文档中找到 aapt 命令行选项和 ant 参数之间映射的简要说明:

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

据我所知,无法通过这个新的构建任务提供通用的 aapt 选项。这似乎只能通过修改 SDK 的 build.xml 副本来实现
替换 aapt 调用。

如果有人知道更好的解决方案,我也很高兴阅读;-)

编辑:在 SDK 的更新版本中,再次引入了重命名包:

Aapt Option   --rename-manifest-package package-name 
Ant Name      manifestpackage
Type          attribute (String)

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)
神也荒唐 2024-12-02 15:48:39

我非常怀疑除了源代码之外还有任何文档。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文