在昨天刚刚发布的 r20 之前,我一直在使用 ant 构建我的项目几个月,没有任何问题。我基本上只是使用默认构建文件提供的钩子(Hook)来做一些小的改动。我的项目正在使用 2 个库项目,构建在 eclipse 中运行良好。但是我使用 ant 进行官方签名构建(我的目标是创建构建,我的应用程序将连接到生产、暂存或 qa 环境)。 这是我收到的错误消息:
BUILD FAILED /Users/mwolfe/workspace/android-flex/app/build.xml:99: The following error occurred while executing this line: /Users/mwolfe/lib/android-sdk/tools/ant/build.xml:476: ../shared/SomeSdk/sdk resolve to a path with no project.properties file for project /Users/mwolfe/workspace/android-flex/shared/SomeSdk/sdk
但是我确定此文件夹中有一个 project.properties 文件,并且之前工作正常。查看 android 的 build.xml 中的第 476 行,它具有以下内容:
<!-- clean target -->
<target name="clean" depends="-setup, -pre-clean"
description="Removes output files created by other targets.">
<delete dir="${out.absolute.dir}" verbose="${verbose}" />
<delete dir="${gen.absolute.dir}" verbose="${verbose}" />
<!-- if we know about a tested project or libraries, we clean them too. -->
<if condition="${project.is.test}">
<then>
<property name="tested.project.absolute.dir" location="${tested.project.dir}" />
<subant failonerror="true">
<fileset dir="${tested.project.absolute.dir}" includes="build.xml" />
<target name="clean" />
</subant>
</then>
</if>
<!-- get all the libraries -->
<if>
<condition><not><isset property="dont.do.deps" /></not></condition>
<then>
<!-- LINE 476 HERE: --> <getlibpath libraryFolderPathOut="project.library.folder.path" />
<if>
<condition>
<isreference refid="project.library.folder.path" />
</condition>
<then>
<!-- clean the libraries with nodeps since we already
know about all the libraries even the indirect one -->
<subant
buildpathref="project.library.folder.path"
antfile="build.xml"
failonerror="true">
<target name="nodeps" />
<target name="clean" />
</subant>
</then>
</if>
</then>
</if>
</target>
知道是什么原因造成的以及如何解决吗?
最佳答案
好吧,我想出了解决办法。发生的事情是,无论出于何种原因,当我最初编写自己的 ant 脚本时,我有自己的干净目标,我将其称为所有子项目的干净目标,如下所示:
<target name="clean" depends="androidbuild.clean">
<exec executable="sh" failonerror="true">
<arg value="${ndk.dir}/ndk-build" />
<arg value="clean" />
</exec>
<!-- remove the next 2 lines to fix the problem -->
<ant target="clean" dir="${android.library.reference.1}" />
<ant target="clean" dir="${android.library.reference.2}" />
</target>
虽然由于某种原因这不再起作用,而且看来新的 ant 构建脚本 android r20 无论如何都为我处理了这个问题,所以删除上面的 2 个干净调用解决了这个问题。
请注意,androidbuild.clean 依赖项会调用 $ANDROID_SDK/tools/ant/build.xml 中定义的父 build.xml 的 clean 目标 当您导入该脚本时,请这样做:
<import file="${sdk.dir}/tools/ant/build.xml" as="androidbuild" />
这样您就可以在该构建文件中引用目标(ps,这也修复了 eclipse 认为您的 build.xml 文件有错误,这样您就不需要将 android build.xml 复制并粘贴到您自己的文件中其他人在线建议)。
关于Android Tools r20 不会使用 ant 使用库项目构建项目,说我在库中缺少 project.properties 但我没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11254569/