我有一个 ant 脚本可以完成它需要做的事情,但我需要根据运行的是发布版还是调试版来设置一些属性值。我该怎么做?
如果有所不同,我的 ant 脚本会在执行 android 构建之前运行一些自定义实用程序任务。
回答我自己的问题:
要查找的属性是“build.mode.release”和“build.mode.debug”,但是有一个警告 ...如果你的 list 有debuggable="true",系统REVERTS到 Debug模式有轻微的“不足”(IMO)
- build.mode.release 未设置,
- build.mode.debug 是 也未设置
- 调试签名已禁用(您必须提供 keystore 、别名和密码)
注意:这仅适用于 Android 版本
最佳答案
“警告”的原因实际上记录在 Android main_rules.xml
项目中 ($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
(通过ant debug
执行),build.mode.release
(当 @debuggable=false
并使用 ant release
执行时),最后满足您的警告:build.packaging.debug
(当 @debuggable=true
并用ant release
)执行
这是一个可以自动预编译的例子:
<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" />
关于java - 在 ant 脚本中检测构建配置(调试或发布),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6218452/