您的項目中可以有一個custom_rules.xml文件,其中包含將您的apk複製到-post-build
目標中所需文件夾的語句。您可以使用copy
任務來照顧它。
要從清單檢索版本信息,請按照SO上的this answer。
的custom_rules.xml的樣品是:
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
<xmlproperty file="AndroidManifest.xml" prefix="mymanifest" collapseAttributes="true"/>
<property name="build.dir" value="bin/${mymanifest.manifest.android:versionName}/" />
<target name="-post-build">
<echo>Version is ${mymanifest.manifest.android:versionName}</echo>
<copy toDir="${build.dir}" >
<fileset file="${out.final.file}" />
</copy>
</target>
</project>
注:目前,APK複製到'bin文件夾的子文件夾。您將不得不考慮另一個目錄,因爲'bin'文件夾將在每個清潔操作中被刪除。
對不起,自從我開始使用ant兩天以來 - 我在哪裏放置了自定義規則文件?我在哪裏可以在build.xml中輸入它。我究竟把它放在什麼位置? – Slartibartfast
在項目根目錄(您擁有build.xml的地方)中創建custom_rules.xml。您不需要對build.xml進行任何更改。但是,您可以打開並嘗試瞭解它是如何工作的 - 它有很好的文檔記錄。 – Rajesh
謝謝!我要試試這個,並回答一些其他問題或者標記這個答案吧:D – Slartibartfast