问题描述
我有一个Ant脚本做的事情需要做,但我需要设置基于我是否运行发布或调试几个属性值。我该怎么做呢?
I have an ant script that does what it needs to do, but I need to set a few property values based on whether I'm running release or debug. How do I do this?
如果它的确与众不同,我的ant脚本执行的Android版本之前运行一些定制的工具的任务。
If it makes a difference, my ant script runs some custom utility tasks before performing android build.
要回答我的问题:
属性,寻找有的 build.mode.release 的和 build.mode.debug 的,但是,现在的警告 ...如果您有明显的可调试=真正的的,系统的恢复以调试模式有轻微的短未来(IMO)
The properties to look for are "build.mode.release" and "build.mode.debug", however there IS a caveat ... if your manifest has debuggable="true", the system REVERTS to debug mode with a slight 'short-coming' (IMO)
- 的 build.mode.release 的是不会设置
- 的 build.mode.debug是的同时不设置
- 签署调试已禁用(你必须提供一个密钥存储,别名和密码)
注意:这仅适用到Android建立
Note: This applies only to Android builds
推荐答案
究其原因,警告在Android的实际记录 main_rules.xml
项目( $ ANDROID_SDK_ROOT /工具/ ANT / main_rules.xml
)
The reason for the "caveat" is actually documented in the Android main_rules.xml
project ($ANDROID_SDK_ROOT/tools/ant/main_rules.xml
):
<target name="-set-release-mode">
<!-- release mode is only valid if the manifest does not explicitly
set debuggable to true. default is false.
We actually store build.packaging.debug, not build.release -->
<xpath input="AndroidManifest.xml" expression="/manifest/application/@android:debuggable"
output="build.packaging.debug" default="false"/>
...
</target>
所以,你要检查什么 build.mode.debug
(通过蚂蚁调试执行
), build.mode.release
(当 @可调试=假
和蚂蚁发布执行
),最后以满足您的警告: build.packaging.debug
(当 @可调试=真
并与执行蚂蚁发布
)
So what you want to check for is build.mode.debug
(executed via ant debug
), build.mode.release
(when @debuggable=false
and executed with ant release
), and finally to meet your caveat: build.packaging.debug
(when @debuggable=true
and executed with ant release
)
下面是将工作$ P $自动对编译一个例子:
Here's an example that would work pre-compile automatically:
<target name="-my-debug-precompile" if="build.mode.debug">
<!-- This is executed for any "debug" build ("ant debug") -->
</target>
<target name="-my-release-precompile" unless="build.mode.debug">
<!-- This is executed for any non-"debug" build (e.g., "ant release",
regardless of the @debuggable attribute in AndroidManifest.xml) -->
</target>
<!-- This is called automatically by Android's ant tasks, and delegates the
task to one of the above two targets: -->
<target name="-pre-compile" depends="-my-debug-precompile,-my-release-precompile" />
这篇关于检测构建配置ant脚本内(调试或释放)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!