Java 检测ant脚本中的构建配置(调试或发布)

Java 检测ant脚本中的构建配置(调试或发布),java,android,configuration,ant,build,Java,Android,Configuration,Ant,Build,我有一个ant脚本来完成它需要做的事情,但我需要根据运行的是release还是debug来设置一些属性值。我该怎么做 如果有区别的话,我的ant脚本会在执行android构建之前运行一些自定义实用程序任务 回答我自己的问题: 要查找的属性是“build.mode.release”和“build.mode.debug”,但是这里有一个警告。。。如果清单中的debuggable=“true”,则系统将恢复到调试模式,并出现轻微的“短路”(IMO) build.mode.release未设置 bui

我有一个ant脚本来完成它需要做的事情,但我需要根据运行的是release还是debug来设置一些属性值。我该怎么做

如果有区别的话,我的ant脚本会在执行android构建之前运行一些自定义实用程序任务


回答我自己的问题:

要查找的属性是“build.mode.release”和“build.mode.debug”,但是这里有一个警告。。。如果清单中的debuggable=“true”,则系统将恢复到调试模式,并出现轻微的“短路”(IMO)

  • build.mode.release未设置
  • build.mode.debug也未设置
  • 已禁用调试签名(必须提供密钥库、别名和密码)
  • 注意:这仅适用于Android构建

    ant-D=
    将在ant中设置属性

    此“警告”的原因实际上记录在Android
    main_rules.xml
    项目中(
    $Android_SDK_ROOT/tools/ant/main_rules.xml
    ):


    作为对Joe答案的更新,看起来至少在Android工具版本22.3中,build.mode.debug属性不再存在,但您可以使用build.is.packaging.debug来区分调试和发布

    ant debug和jni模块的最终解决方案:
    1.在custom_rules.xml中,将调试模式分配给“BUILDMODE”

    <?xml version="1.0" encoding="UTF-8"?>
    <project>
            <property name="out.library.jar.file" location="bin/classes.jar" />
        <target name="-pre-compile">
                    <exec executable="ndk-build">
                            <arg value="BUILDMODE=${build.is.packaging.debug}" />
                    </exec>
        </target>
    </project>
    
    
    
  • jni/Android.mk,添加以下内容:
  • ifeq($(构建模式),true)
    LOCAL\u CFLAGS=-DDEBUG


    endif

    我知道这一点,但我看不出其中的条件部分。我想加载两个文件中的一个(release.properties/debug.properties),或者根据配置在脚本中手动设置属性值。以目录路径为例,我想要out/release和out/debug@copolii使用任务:我知道条件任务,我需要实际条件。。。如果使用“ant release”执行ant脚本,则计算结果为true,使用“ant debug”执行结果为false,反之亦然。一定有什么地方有财产。。。i、 e.在VisualStudio/MSBuild中,它是$(配置),其计算结果为“release”或“debug”main_规则,我在其中找到了我发布的信息。谢谢:)@copolii:我详细说明的原因是因为您没有提到第三个属性(
    build.packaging.debug
    )——当应用程序本应处于发布模式(
    ant release
    )时,这是正确的,但由于
    @debugable=true
    )而被迫返回到调试版本,并且也没有明确指出您的“警告”他说。我还意识到你已经有了一个对你有用的解决方案,你用语言描述了这个解决方案,但既然是这样,其他人稍后会偶然发现这个问题,那么有一个详细的例子对其他人来说是有用的;这就是目标的例子。我花了好几个小时的时间才无意中发现。这一点怎么强调也不过分。实际上,它现在是
    build.is.packaging.debug
    <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" />
    
    <?xml version="1.0" encoding="UTF-8"?>
    <project>
            <property name="out.library.jar.file" location="bin/classes.jar" />
        <target name="-pre-compile">
                    <exec executable="ndk-build">
                            <arg value="BUILDMODE=${build.is.packaging.debug}" />
                    </exec>
        </target>
    </project>