我正在研究这个问题超过一个小时:
我有一个android项目,因为我在编译时做自定义步骤,我使用ANT编译项目并生成APK文件。
1-如果我使用ant:
的“愚蠢”命令行ant init_debug
编译android应用程序并创建apk文件;它通过我的自定义步骤(我有“echo”指令显示我的自定义步骤,它们在命令行中打印)。
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以&lt; project&gt;开头。用我的项目名称,所以我尝试了“myproject.clean”而不是简单地“干净”作为依赖而没有成功
d)我也试过“android_rules.clean”,结果相同
e)我的custom_build.xml也以&lt; project&gt;开头,但我没有添加任何名称属性。
我的想法已经用完了,欢迎任何帮助!
我的完整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>
提前致谢! 汤姆。