【发布时间】:2014-07-23 21:51:21
【问题描述】:
我正在尝试使用自定义构建文件来在我的 Android 应用程序中显示当前的 git 版本。我以前没有使用过 ant,我也不知道如何使用它。我在 SO 中阅读了很多主题,并在 Google 中进行了很多搜索,但我无法弄清楚。我真的没有时间学习关于 ant 的一切,但我需要运行这个东西。在底部,您可以找到代码。
当前状态
文件custom_rules.xml被导入到Eclipse创建的build.xml中。 macrodef 部分被调用,但目标不被调用。我尝试更改External Tools Configurations,标签Targets,但每当我检查目标(无论在哪个ant文件中)时,都会收到一条消息:
Unknown argument: -pre-build
例如(当我在-pre-build 上打勾时)。我尝试添加这一行:
<import file="${sdk.dir}/tools/ant/build.xml" />
并定义 sdk.dir 但这并没有改变任何东西。我错过了什么?正如我所说,我对蚂蚁一无所知,唯一对我有帮助的教程是this one。
当前代码 (custom_rules.xml)
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse.ant.import ?>
<project name="Custom build">
<macrodef name="git" taskname="@{taskname}">
<attribute name="command" />
<attribute name="dir" default="" />
<attribute name="property" default="" />
<attribute name="taskname" default="" />
<attribute name="failonerror" default="on" />
<element name="args" optional="true" />
<sequential>
<exec executable="git" dir="@{dir}" outputproperty="@{property}"
failifexecutionfails="@{failonerror}" failonerror="@{failonerror}">
<arg value="@{command}" />
<args/>
</exec>
</sequential>
</macrodef>
<target name="-pre-build">
<git command="rev-list" property="versioning.code" taskname="versioning">
<args>
<arg value="master" />
<arg value="--first-parent" />
<arg value="--count" />
</args>
</git>
<git command="describe" property="versioning.name" taskname="versioning">
<args>
<arg value="--always" />
</args>
</git>
<echo level="info" taskname="versioning">${versioning.code}, ${versioning.name}</echo>
<replaceregexp file="AndroidManifest.xml" match='android:versionCode=".*"' replace='android:versionCode="${versioning.code}"' />
<replaceregexp file="AndroidManifest.xml" match='android:versionName=".*"' replace='android:versionName="${versioning.name}"' />
</target>
<target name="-post-build" >
<replaceregexp file="AndroidManifest.xml" match='android:versionCode=".*"' replace='android:versionCode="0"' />
<replaceregexp file="AndroidManifest.xml" match='android:versionName=".*"' replace='android:versionName="0"' />
</target>
</project>
【问题讨论】:
标签: android eclipse git ant build