我有一个依赖于三个 android 库的 Android 项目。它的 project.properties 文件如下所示:
split.density=false
android.library.reference.2=..\\LibB
proguard.config=proguard.cfg
android.library.reference.1=..\\\\LibA\\\\
# Project target.
target=android-5
android.library.reference.3=../LibC
该项目的 build.xml 仅用于依赖 Gradle 任务:
<target name="-pre-build" depends="preBuild" />
<target name="-pre-compile" depends="preCompile" />
<import file="${sdk.dir}/tools/ant/build.xml" />
build.gradle 以下列方式包含项目的 build.xml:
ant.property(file: 'local.properties')
configurations {
sdkDir = ant.properties['sdk.dir']
}
ant.importBuild "build.xml"
当我使用“发布”目标运行此脚本时,我从 Android 的 build.xml 文件中收到以下错误:
[ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':-build-setup'.
[ERROR] [org.gradle.BuildExceptionReporter] Cause: The following error occurred while executing this line:
[ERROR] [org.gradle.BuildExceptionReporter] Target "${build.target}" does not exist in the project "LibA".
这是由第 466 行(包含“subant”的行)引起的:
<!-- compile the libraries if any -->
<if>
<condition>
<isreference refid="project.libraries" />
</condition>
<then>
<echo>Building Libraries</echo>
<subant
buildpathref="project.libraries"
antfile="build.xml"
target="${build.target}"
failonerror="true"/>
<echo></echo>
<echo>############################################</echo>
<echo>**** Back to project ${ant.project.name} ****</echo>
<echo>############################################</echo>
</then>
</if>
所以,问题是:有人知道如何摆脱这个错误或如何在 Gradle 中正确使用 Android 的 build.xml 吗?
Gradle-android-plugin 目前对于 android sdk >= r14 已损坏,因此我已不再依赖它。我使用 sdk 工具 r15。
更新:
似乎两者都没有
<target name="-set-release-mode" depends="-set-mode-check">
也不
<target name="-set-debug-mode">
在 Android 的 build.xml 文件中被调用,但我不知道为什么。