Inserting build target using build.xml only?
I have a build.xml which is capable of compiling and optimizing if I run the build targets individually - "ant compile" followe开发者_高级运维d 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?
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
.
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)
精彩评论