在 ant 脚本中检测构建配置(调试或发布) [英] detecting build configuration (debug or release) within ant script

查看:41
本文介绍了在 ant 脚本中检测构建配置(调试或发布)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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",但是有一个警告 ...如果您的清单具有debuggable="true",系统恢复到调试模式,但有轻微的缺点"(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)

  1. build.mode.release 未设置
  2. build.mode.debug 是 也没有设置
  3. 调试签名已禁用(您必须提供密钥库、别名和密码)

注意:这仅适用于 Android 版本

Note: This applies only to Android builds

推荐答案

警告"的原因实际上记录在 Android main_rules.xml 项目 ($ANDROID_SDK_ROOT/tools/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(通过ant debug执行),build.mode.release(当 @debuggable=false 并用 ant release 执行),最后满足你的警告:build.packaging.debug(当 @debuggable=true 并使用 ant release)

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)

这是一个可以自动预编译的示例:

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 脚本中检测构建配置(调试或发布)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆