私はそれに1時間以上取り組んでいます:
Android プロジェクトがあり、コンパイル時にカスタム手順を実行しているため、ANT を使用してプロジェクトをコンパイルし、APK ファイルを生成しています。
1-antで「愚かな」コマンドラインを使用する場合:
ant init_debug
Android アプリケーションがコンパイルされ、apk ファイルが作成されます。カスタムステップを通過します(カスタムステップを表示する「エコー」命令があり、それらはコマンドラインに出力されます)。
2- Eclipse にカスタム ビルド ファイルを実行するように依頼すると、失敗し、Eclipse が次のように応答します。
Buildfile: /home/[...]/custom_rules.xml
BUILD FAILED
Target "clean" does not exist in the project "null". It is used from target "myrelease".
Total time: 95 milliseconds
そして、24行目は何ですか?<target> での通常の一般的な依存関係の宣言
<target name="init_debug" description="Initialize pre build and do DEBUG" depends="clean, debug">
a) 「android update project -p」を実行します。数回
b) Eclipse を閉じて再度開きました (試してみる価値があります! 過去にそのように奇妙なことが解決されたのを見たことがあります!)
c) 私の build.xml はプロジェクト名の <project> で始まるので、依存関係として単に "clean" ではなく "myproject.clean" を試してみましたが成功しませんでした
d)「android_rules.clean」も試しましたが、同じ結果でした
e) name プロパティを入れていませんが、custom_build.xml も <project> で始まります。
アイデアが不足しています。どんな助けも大歓迎です!
私の完全な custom_rules.xml は次のとおりです。
<!--?eclipse.ant.import ?-->
<project default="init_debug">
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- +++++++++++++++++++++++++++++++++++++++ DEBUG & RELEASE ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<target name="init_release" description="Initialize pre build and do RELEASE">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="/home/tomtom/dev/apache-ant/lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<antcall target="myrelease">
<param name="debugMode" value="false"/>
</antcall>
</target>
<target name="init_debug" description="Initialize pre build and do DEBUG">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="/home/tomtom/dev/apache-ant/lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<antcall target="mydebug">
<param name="debugMode" value="true"/>
</antcall>
</target>
<target name="myrelease" description="Performs Clean + Compile RELEASE" depends="clean, release">
<echo>--- RUNNING CUSTOM RELEASE ---</echo>
</target>
<target name="mydebug" description="Performs Clean + Compile DEBUG" depends="clean, debug">
<echo>--- RUNNING CUSTOM DEBUG ---</echo>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++++++ PRE- & POST-BUILD +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<target name="-pre-build" depends="-strings_manipulations">
<antcall target="-update_manifest_xml"/>
<antcall target="-update_strings_xml"/>
<antcall target="-update_bool_xml"/>
</target>
<target name="-post-build">
<!--antcall target="-restore_manifest_xml"/>
<antcall target="-restore_strings_xml"/>
<antcall target="-restore_bool_xml"/-->
<antcall target="-echo_strings"/>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++++++++ UPDATE FILES ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<target name="-update_manifest_xml">
<echo>--- RUNNING UPDATE_MANIFEST ---</echo>
<antcall target="-manifest_manipulation">
<param name="manifest_path" value=""/>
</target>
<target name="-update_strings_xml">
<echo>--- RUNNING UPDATE_STRINGS ---</echo>
<copy
file="res/values/strings.xml"
tofile=".strings.xml.antbak"
preservelastmodified="true"
/>
<property name="v.start.string" value='<string name="app_version">' />
<property name="end.string" value="</string>" />
<replaceregexp
file="res/values/strings.xml"
match="${v.start.string}.*${end.string}"
replace="${v.start.string}${version.string}${end.string}"
/>
<property name="c.start" value='<string name="app_linesofcode">' />
<replaceregexp
file="res/values/strings.xml"
match="${c.start}.*${end.string}"
replace="${c.start}${linesOfCode}${end.string}"
/>
</target>
<target name="-update_bool_xml">
<echo>--- RUNNING UPDATE_BOOLEAN (${debugMode}) ---</echo>
<copy
file="res/values/bool.xml"
tofile=".bool.xml.antbak"
preservelastmodified="true"
/>
<property name="start.bool" value='<bool name="DEBUG_MODE">'/>
<property name="end.bool" value="</bool>"/>
<replaceregexp
file="res/values/bool.xml"
match="${start.bool}.*${end.bool}"
replace="${start.bool}${debugMode}${end.bool}"
/>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++++++++ RESTORE FILES +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<target name="-restore_manifest_xml">
<echo>Restoring backup of AndroidManifest.xml</echo>
<move
file=".AndroidManifest.xml.antbak"
tofile="AndroidManifest.xml"
preservelastmodified="true"
overwrite="true"
/>
</target>
<target name="-restore_strings_xml">
<echo>Restoring backup of strings.xml</echo>
<move
file=".strings.xml.antbak"
tofile="res/values/strings.xml"
preservelastmodified="true"
overwrite="true"
/>
</target>
<target name="-restore_bool_xml">
<echo>Restoring backup of bool.xml</echo>
<move
file=".bool.xml.antbak"
tofile="res/values/bool.xml"
preservelastmodified="true"
overwrite="true"
/>
</target>
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++++ STRING MANIPULATIONS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<target name="-strings_manipulations">
<exec executable="cloc" output="code">
<arg value="${basedir}"></arg>
</exec>
<loadfile srcFile="code" property="linesOfCode">
<filterchain>
<containsregex pattern="^SUM:.*[0-9]*$" />
</filterchain>
</loadfile>
<propertyregex
property="linesOfCode"
override="true"
input="${linesOfCode}"
regexp="SUM:\s*\d*\s*\d*\s*\d*\s*(\d*)"
select="\1"
/>
<buildnumber file="build.num"/>
<property name="version.AppCode" value="2"/>
<property name="version.number" value="1"/>
<property name="version.revision" value="0"/>
<property name="version.string" value="${version.AppCode}.${version.number}.${version.revision}.${build.number}" />
</target>
<target name="-manifest_manipulation">
<property name="start.manifest.name" value='android:versionName="' />
<property name="end.manifest.name" value='">' />
<echo>Manifest Path: ${manifest_path}AndroidManifest.xml</echo>
<copy
file="${manifest_path}AndroidManifest.xml"
tofile="${manifest_path}.AndroidManifest.xml.antbak"
preservelastmodified="true"
/>
<replaceregexp
file="${manifest_path}AndroidManifest.xml"
match="${start.manifest.name}.*${end.manifest.name}"
replace="${start.manifest.name}${version.string}${end.manifest.name}"
/>
<property name="start.manifest.code" value='android:versionCode="' />
<property name="end.manifest.code" value='"' />
<replaceregexp
file="${manifest_path}AndroidManifest.xml"
match="${start.manifest.code}.*${end.manifest.code}"
replace="${start.manifest.code}${version.AppCode}${end.manifest.code}"
/>
</target>
<target name="-echo_strings">
<echo>++++++++++++++++++++++++++++++++++++++</echo>
<echo>++</echo>
<echo>++ Lines of Code: ${linesOfCode}</echo>
<echo>++</echo>
<echo>++ Version Code : ${version.string}</echo>
<echo>++</echo>
<echo>++ DEBUG MODE : ${debugMode}</echo>
<echo>++</echo>
<echo>++++++++++++++++++++++++++++++++++++++</echo>
</target>
</project>
前もって感謝します!トム。