我为此工作了一个多小时:
我有一个 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更新项目-p”。几次
b)我关闭并重新打开了 Eclipse(值得一试!我曾经看到过像这样解决奇怪的事情!)
c)我的 build.xml 以 <project> 开头,并带有我的项目名称,所以我尝试了“myproject.clean”而不是简单地“clean”作为依赖项但没有成功
d)我也尝试了“android_rules.clean”,结果相同
e) 我的 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>
提前致谢!汤姆。