仅使用 build.xml 插入构建目标?

发布于 2024-10-20 14:57:47 字数 610 浏览 1 评论 0原文

我有一个 build.xml,如果我单独运行构建目标,它能够编译和优化 - “ant 编译”后跟“并优化”。

问题是,我想运行“ant release”,它通常会执行生成发布二进制文件所需的一切,但我需要将构建目标插入到链中 - 该目标称为“optimize”,并且它运行 proguard 优化/shrinker 在“dex”阶段构建字节码之前针对类文件。

模板文件 /opt/android-sdk-linux_x86/platforms/android-8/templates/android_rules.xml 包含以下规则,我可以修改为“depends=”compile,optimize””但我不想必须针对每个不同的 SDK 重新修改该文件(每次都使用新的 android_rules.xml 文件)。

<!-- Converts this project's .class files into .dex files -->
<target name="-dex" depends="compile">
    <dex-helper />
</target>

是否有其他方法可以修改模板 xml 并将所有编译规则放入 build.xml 中?

I have a build.xml which is capable of compiling and optimizing if I run the build targets individually - "ant compile" followed by "and optimize".

The problem is, that I want to run "ant release" which would normally do Everything necessary to produce the release binary, but I need to insert a build target to the chain - the target is called "optimize" and it runs a proguard optimize/shrinker against the class files just before the "dex" stage builds the byte code.

The template file /opt/android-sdk-linux_x86/platforms/android-8/templates/android_rules.xml contains the following rule, which I could modify to say "depends="compile,optimize" " But I don't want to have to re-modify the file for every different SDK that comes out (with a new android_rules.xml file each time).

<!-- Converts this project's .class files into .dex files -->
<target name="-dex" depends="compile">
    <dex-helper />
</target>

Is there an alternative to modifying the template xml and instead putting all compile rules into the build.xml?

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

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

发布评论

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

评论(2

爱殇璃 2024-10-27 14:57:47

为什么不在模板 build.xml 文件中使用编译后挂钩?它写道:

[This is typically used for code obfuscation.
 Compiled code location: ${out.classes.absolute.dir}
 If this is not done in place, override ${out.dex.input.absolute.dir}]
<target name="-post-compile">
</target>

鉴于它明确要求修改,我认为跨 sdk 版本将支持它。

要查看为您的项目自动生成的完整 build.xml 文件,您可能需要运行 android update project

Why not use the post-compile hook in the template build.xml file? It reads:

[This is typically used for code obfuscation.
 Compiled code location: ${out.classes.absolute.dir}
 If this is not done in place, override ${out.dex.input.absolute.dir}]
<target name="-post-compile">
</target>

Given that it's there explicitly asking for modification, I would think that it would be supported across sdk versions.

To see the full auto-generated build.xml file for your project you may need to run android update project.

深府石板幽径 2024-10-27 14:57:47

以防万一您错过了:

从 SDK Tools Rev 8 开始,内置了 Proguard 支持。您只需将该行添加

proguard.config=proguard.cfg

到 default.properties(当然还有一个 proguard.cfg 文件,您可以在其中设置混淆规则) )

您不需要添加任何其他目标。

(无论如何,Windows 版本都是如此,我想 Linux 也是如此。“rules”xml 现在称为 main_rules.xml)

Just in case you missed it:

As of SDK Tools Rev 8, Proguard support is built in. You just need to add the line

proguard.config=proguard.cfg

to your default.properties (and have a proguard.cfg file of course, where you set up your obfuscation rules)

You don't need to add any other targets.

(This is true in the Windows version anyway, I imagine it's the same for Linux. The 'rules' xml is now called main_rules.xml)

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