【问题标题】:How to explain this ant build file?如何解释这个 ant 构建文件?
【发布时间】:2015-08-06 14:05:23
【问题描述】:

我使用 android.bat 为我的 android 项目创建 ant build.xml。

现在我在 build.xml 中找到了这些代码:

<!-- if sdk.dir was not set from one of the property file, then
     get it from the ANDROID_HOME env var.
     This must be done before we load project.properties since
     the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
    <isset property="env.ANDROID_HOME" />
</condition>

但我认为这段代码意味着如果设置了env.ANDROID_HOMEsdk.dir 将是${env.ANDROID_HOME}。此代码如何检查sdk.dir 是否已设置?

为什么要投反对票?在 Apache Ant 用户手册中:

如果条件成立,则属性值默认设置为true;否则,不设置该属性。您可以通过指定 value 属性将值设置为默认值以外的值。

它只是说该属性将根据条件的结果设置为某个值。我不明白意思:If the property is set , the condition won't work.

【问题讨论】:

    标签: android ant


    【解决方案1】:

    除非您使用 local 范围,否则 Ant 中的属性是 immutable

    因此,如果 sdk.dir 之前从属性文件中设置,则条件中的第二个赋值将被忽略。

    您可以运行ant -verbose 来查看发生了什么。

    【讨论】:

      猜你喜欢
      • 2022-06-23
      • 1970-01-01
      • 2020-04-08
      • 1970-01-01
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      • 1970-01-01
      • 2012-02-06
      相关资源
      最近更新 更多