[英]Ant build in Eclipse
我正在嘗試使用自定義生成文件,以便在我的Android應用程序中顯示當前的git版本。 我以前沒有使用過螞蟻,也沒有真正知道如何使用它。 我在SO中閱讀了大量主題,並在Google中搜索了很多內容,但我無法弄清楚。 我真的沒有時間學習有關螞蟻的所有知識,但我需要運行此工具。 在底部,您可以找到代碼。
當前狀態
文件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
但不會改變任何內容。 我想念什么? 就像我說的那樣,我對螞蟻一無所知,唯一幫助我的教程就是這篇 。
當前代碼( 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>
我只是想通了。
-
pre-build
和post-build
。 External Tools Configurations
然后在左側選擇了build.xml
。 在右側,我轉到“ Targets
”選項卡,檢查了我的兩個目標(除了已經具有復選標記的build
目標之外),並將順序設置為pre-build, build, post-build
。 Builders
。 我使用build.xml
文件創建了一個新的構建器,並以相同的順序具有上一個項目符號點中的三個目標。 我將此構建器放在Java構建器之前。 post-build
目標,因為它會將版本恢復為0
而且似乎比我希望的早。 我仍然不確定這是否是最佳解決方案。 另外,當沒有git版本控制時,解決方案也會失敗。 我嘗試使用此代碼解決問題,但沒有成功。 不過,這是我能做的最好的事情,它可以幫助我在應用程序中獲取所需的信息。
將Git可執行文件與Argument --version
一起使用,並在屬性中捕獲輸出以進一步使用fe:
<project>
<exec executable="git" outputproperty="gitversion">
<arg value="--version"/>
</exec>
<echo>$${gitversion} => ${gitversion}</echo>
</project>
輸出:
[echo] ${gitversion} => git version 1.8.3.msysgit.0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.